“HABEMUS PACTUM!” tweeted Vlora Citaku, Kosovo’s minister for European integration. Serbia and Kosovo had just reached a deal. It came on April 19th after ten grueling rounds of negotiation between the prime ministers of the two countries under the personal supervision of Baroness Ashton, the European Union’s foreign policy chief (pictured above). The deal is a huge breakthrough for the two countries, for the western Balkans as a whole and a triumph for Lady Ashton and her team. On April 2nd , after eight rounds, it seemed possible that the whole process had failed.

The deal was initialed by Hashim Thaci, the prime minister of Kosovo, who is a former leader of the Kosovo Liberation Army, a guerrilla force which fought the Serbs in 1998-99. He negotiated with Ivica Dacic, the Serbian prime minister who, during the Balkan wars of the 1990s was a close associate of Slobodan Milosevic, the then Serbian leader. Also present was Aleksandar Vucic, the Serbian deputy prime minister, a former extreme nationalist.

The agreement unlocks the way for both countries to continue on their path to EU integration. Implicit is the understanding that, by making the agreement, Serbia will be now be given a green light to open EU accession talks. Kosovo will get a formal commitment to negotiating an earlier step in the process, known as a Stabilisation and Association Agreement.

The 15-point agreement (scroll down for English) is expected to be formally endorsed by the two governments and parliaments in the next 48 hours.

Kosovo, with its majority Albanian population declared independence from Serbia in 2008. It had not been under Serbian control since the end of the Kosovo war in 1999. Kosovo is now recognised by just under 100 countries (the exact number is disputed) but not Serbia, Russia, China and five of 27 EU countries.

The deal is being hailed by diplomats and politicians in both countries as a “win-win” situation although it will be resisted by hard-line nationalists on both sides. Still, Petrit Selimi, Kosovo’s deputy foreign minister was certainly right when he said yesterday, while attending Globsec, a global security conference in Bratislava in Slovakia, a country that does not recognise Kosovo that: “The dam has been broken. There is no way back.”

The essence of the deal is that while Serbia does not recognise Kosovo as a state, it concedes its legal authority over the whole territory. In exchange the Kosovo authorities concede a level of autonomy to four Serb-controlled areas of northern Kosovo. They will set up an association, which will take care of education and health and other matters. The deal says that there will be one police force in Kosovo but that the Serb regional commander for the north will be chosen from a list nominated by the mayors of the north.

A compromise formula was found over the vexed issue of courts and elections are to be held this year for the northern municipalities which are now elected under the Serbian not Kosovo system.

There are believed to be some 140,000 Serbs in Kosovo out of a total population of 1.7m. About one third of them live in the north. The rest live in areas of Kosovo which, in the last few years, have begun to integrate into the rest of the country in terms of municipal organsations, though not in terms of education and health. Some of these areas could accede to the new Serbian association.

The deal does not prevent Serbia from funding education and other services as it does now. According to Mr Dacic and Mr Selimi, the Kosovo Security Force, Kosovo’s de facto army, will not deploy in the north, at least for some years. Following the making of the deal Lady Ashton, Mr Dacic and Mr Thaci went to visit NATO to discuss help in implementing the deal. A photo showed them together on the same side of the table talking to NATO chiefs, not facing one another as they have until now.

Kosovo Serb leaders in the north have said they will do all they can to oppose the deal, and even talked in the past few weeks of some form of secession from Kosovo. In February last year Kosovo Serbs in the north voted overwhelmingly to reject any cooperation with the authorities in the south. In the long run their objections look set to be in vain.

Sources in the north believe that once the message comes from the authorities in Belgrade that it is in the interests of the Serbian state for Kosovo Serbs to fall into line, they will do so. Money will certainly play a role here. As leaders of newly elected municipalities, recognised as legal by both Kosovo and Serbia they could be set for a financial windfall. Reintegrated into Kosovo they will receive money from the central government and also from Serbia.

A previous deal also means they will get a good proportion of customs receipts from the two northern border points to Serbia. The EU and the US, which played a crucial but behind the scenes role in securing the deal will also doubtless make funds available.

Failure to strike deal could have had dire consequences for Serbia, Kosovo and the rest of the region. Outsiders would have concluded that the parties were so stubborn and unwilling to take risks for the best interests of their people that it was no longer worth bothering trying to help them. A long period of stagnation would almost certainly have set in.

Implementation of the deal will certainly be difficult but a huge psychological barrier has been passed. With Serbia and Kosovo moving ahead in terms of their mutual relations and in terms of European integration diplomats hope that their example will give a prod to both the Bosnians, who are now lagging behind because of a failure to make similar necessary compromises, and the Macedonians.

The talks are a rare success for EU foreign policy. They began in March 2011 when Boris Tadic was in power in Serbia. They moved up from so-called technical talks to the political level in September last year.

Until now Serbian officials have attempted to avoid contact with their Kosovar counterparts. In Bratislava however it was clear that there was a new spirit. Both sides toasted the deal. “All of us are winners,” said one Serbian official who asked to remain nameless. He added prudently, that equally both sides would do well to “avoid triumphalism.”