After an astonishing 27 years at odds, in June, Macedonia and Greece reached a dramatic breakthrough in negotiations over what’s known as the Macedonia naming dispute. The dispute was, yes, over the former Yugoslavian nation’s name — but over much more as well, as we’ll see below. And after all that time, the June agreement solved the dispute simply: by renaming Macedonia as the “Republic of North Macedonia.”

What was at stake here — and why did resolving it take nearly three decades? Examining the long and complicated process can teach us a few practical lessons about international mediation.

A brief history of the naming dispute

In 1991, Macedonia declared independence from Yugoslavia and wrote into its constitution that its name was the Republic of Macedonia. The new nation’s southern neighbor, Greece, immediately opposed this, arguing that it implied territorial claims over Greece’s northern region — also called Macedonia.

That geographical claim has some history. Since the region was divided during the Ottoman Empire’s dissolution, various partisans have attempted to reunite broader Macedonia, which includes the present-day nation, northern Greece and southwestern Bulgaria.

But underlying this territorial dispute was one over which nation could claim the ancient Macedonian kingdom — birthplace and homeland of Alexander the Great — as its national heritage.

For almost three decades, neither side would budge from its core demands.

Greece demanded that “Macedonia” must not appear anywhere in the new nation’s name and insisted that its constitution be changed to eliminate that word as well. Macedonia was willing to take a different name for international use but refused to change its constitution.

At times, the standoff threatened the stability of the Balkans. In the 1990s, Greece blocked Macedonian attempts to join the United Nations and imposed an economic embargo. In 2008, Greece vetoed Macedonian membership in NATO, citing the stalemate over Macedonia’s name. A year later, Greece blocked Macedonia’s bid for E.U. membership.

Twice, the countries relaxed tensions slightly, but without reaching a real solution. In 1993, Macedonia agreed to use the name Former Yugoslav Republic of Macedonia (FYROM) in return for U.N. membership. And in 1995, in an interim agreement, Macedonia agreed to change its flag and confirmed that it had no territorial ambitions over the Greek province of Macedonia. In return, Greece promised not to block Macedonian attempts to join international organizations.

But agreement over the name remained elusive — which blocked Macedonia’s membership in the European Union and NATO, despite accession support from both these institutions. The European Union and NATO fear that leaving Macedonia out might bolster Russia, which has engaged in activities aimed at preventing Balkan countries from joining NATO and succumbing to Western influence.

So how did Macedonia and Greece finally resolve the naming dispute?

Three factors allowed Macedonia and Greece to finally reach a solution to their long-standing dispute: proper timing for negotiation, high-intensity negotiations and relaxation of core demands. Let’s look at each of these.

1. Timing of the negotiations

In 2017, a new pro-Western government came to power in Macedonia. Led by Prime Minister Zoran Zaev, the government was eager to move ahead with integrating into Europe and the Atlantic alliance — and quickly reopened negotiations with Greece, mediated by U.N. envoy Matthew Nimetz.

By 2017, the conflict had reached what researchers call a “hurting stalemate”: a situation in which all parties would gain more from solving the conflict than from continuing it. Macedonia wanted E.U. and NATO memberships, which were contingent upon reaching a deal with Greece. The Greek side wanted to capitalize on Zaev’s willingness to amend the Macedonian constitution — a Greek demand that had been rejected by previous Skopje administrations. This made the timing for negotiations favorable, with both sides wanting the dispute over.

2. Intensity of the negotiations

With both sides motivated, the talks became intense — and productive.

Greece and Macedonia reached several low points during the negotiations — but kept pushing for a solution. In May, Nimetz described the negotiations as “very serious, hard-working, and intense.”

3. Willingness to compromise on bottom-line demands

Shortly after entering negotiations, Macedonia’s prime minister stated that absolute demands “only serve as obstacles to finding a solution.” Nimetz skillfully moved to relax the parties’ bottom lines and emphasized clearly formulating what each side wanted in a solution.

Greece wanted a name that clearly distinguished between the Greek region of Macedonia and the new country and asked for constitutional changes to guarantee the longevity of the new name. Macedonia sought a name that preserved a Macedonian identity, as well as guarantees that Greece would not block European Union or NATO membership.

The final agreement satisfied these demands — but with significant concessions from both.

First, the agreement distinguished the ancient Hellenic heritage linked to Alexander the Great from the Macedonian cultural identity — a huge concession by Macedonia, considering the history of claims to Alexander. Macedonia also agreed to adopt a new name qualified with the geographic identification “North,” and to change its constitution to reflect the new name.

Greece agreed to recognize the nation’s right to use the Macedonian language and a Macedonian identity, overcoming previous refusals to do either.

It’s not over until it’s over

Both nations now have to get their legislatures to ratify the agreement, which could be rocky. But the negotiated solution is already changing the European landscape. The European Union recommended starting accession talks with Macedonia to begin in 2019. NATO leaders officially invited Macedonia to join.

If ratified, this agreement will not only end the unusual dispute between Macedonia and Greece, but will also serve as an important case study of successful international mediation.

Danilo Gjukovikj (@DaniloGjukovikj) is a PhD student in international relations at the University of Colorado at Boulder.