Amsterdam on Monday won a fierce fight to host the European Medicines Agency after it leaves London, securing one of the most prized spoils of Britain's decision to leave the EU.
The Dutch city beat Milan in a tiebreak after three rounds of secret voting by the 27 EU member states without Britain failed to produce an outright winner, officials said.
The new location for the European Banking Authority will be decided later Monday, with both London-based agencies up for grabs as a result of last year's shock Brexit vote.
EU President Donald Tusk said on Twitter before the vote that "whatever the outcome, the real winner of today's vote is EU27. Organised and getting ready for Brexit."
Diplomats compared the complex voting process to the annual Eurovision Song Contest. The production's nail-biting televised voting sequence is one of the most watched TV moments in Europe and is known for its come-from-behind surprises.
Copenhagen was in third place.
Together the two agencies account for 1,000 jobs, as well as bringing both prestige to the host country and an economic boost in the form of tens of thousands of visitors every year.
The battle for both agencies has been bitterly contested with governments jostling to win the backing of other countries with "hot bargaining" behind the scenes, a diplomatic source told AFP.
But it has also been deeply political. Axed Catalan leader Carles Puigdemont said that Barcelona had been the "favourite" but that the "state had condemned it", blaming violence over the region's disputed independence vote.
There were 16 candidates to be the new home of the EMA, one of the world's most powerful drugs watchdogs, which employs 900 pharmaceutical experts, biologists and doctors from every corner of Europe.
There is a smaller batch of eight bidders for the EBA, the banking regulator with 159 staff. The EBA is perhaps best known for its regular stress tests on the EU's financial sector in the wake of the global financial crisis.
Both are currently based in London's Docklands business district but must move when Britain leaves the bloc in March 2019 because EU agencies are not allowed to be based outside the union.
Member states brought out all the stops to extol the merits of their candidate cities, producing glossy brochures and videos and offering a host of perks.
The Irish government had said it was willing to contribute 78 million euros ($91.5 million) over 10 years to cover costs, while Vienna promised a children's nursery, and Milan threw in access to a gym.
Italy was even forced to deny news reports that it would increase its military contingents to the Baltic countries as a bargaining chip to promote Milan's candidacy.
In an unusually complex procedure—even for the EU—each country had six points to distribute for each agency in the first round of voting, including three to give to their first choice, two to their second and one to their third.
In the second and third rounds they had one point each to distribute. In the end, Amsterdam and Milan had to draw lots.
One diplomatic source said his country had resorted to studying "game theory" to be ready.
The European Commission, the EU's executive arm, delivered an evaluation of the applications in September based on a range of criteria from transport links, to job prospects for spouses and schools.
But the staff of the agencies in question, already being forced to up sticks from London, had reportedly nervous about some of the candidates, reportedly including Bratislava, Warsaw, Bucharest and Sofia.
Explore further: Dutch bid to be new home for EU medicine agency