Spain said on Thursday that it will join South Africa's case at the UN's top court in which Pretoria has accused Israel of genocide in the Gaza Strip.
"Our sole goal is to put an end to the war and to advance on the road of applying the two-state solution", Foreign Minister Jose Manuel Albares said at a press conference.
His statement came a week after Spain, along with Ireland and Norway, recognised the state of Palestine, sparking fury from Israel.
South Africa brought the case before the International Court of Justice last year, alleging that Israel's Gaza offensive, launched in retaliation for an unprecedented Hamas attack on Israel, breached the 1948 UN Genocide Convention.
Israel has strongly denied the accusation.
Set up after World War II, the Hague-based ICJ rules in disputes between states.
The ICJ on Friday ordered Israel to ensure "unimpeded access" to UN-mandated investigators to look into allegations of genocide.
In a ruling on 26 January, the ICJ also ordered Israel to do everything it could to prevent acts of genocide during its military operation in Gaza.
However, South Africa has since returned several times to the ICJ, arguing that the dire humanitarian situation in the territory compels the court to issue further emergency measures.
On 24 May, the court ordered Israel to "immediately" halt its military offensive in the city of Rafah and keep open the key border crossing there for "unhindered" humanitarian aid.
It also called for the "unconditional" release of captives taken by the Palestinian group Hamas during its 7 October assault.
ICJ rulings are legally binding, but the court has no concrete means to enforce them. For example, it ordered Russia to halt its invasion of Ukraine, to no avail.