|By Gabriela Baczynska and Alastair Macdonald

|By Gabriela Baczynska and Alastair Macdonald

BRUSSELS (Reuters) - Amsterdam and Paris won the right to host two EU agencies that must leave London because of Brexit after an extraordinary ministerial meeting in Brussels that left both results decided by drawing lots from a fishbowl.

The European Medicines Authority (EMA), a key element in the continent's healthcare industry, will go to Amsterdam, which tied with favorite Milan; the European Banking Authority (EBA) will go to Paris, winner in the lucky dip over Dublin, which won some sympathy votes due to the pain Brexit is causing Ireland.

Among other big losers was Frankfurt, whose rivalry with Paris to displace London as the EU's main financial center once Britain leaves the bloc in 2019 took a hit when it finished a distant third in the three-way, second-round vote for the EBA, which sets rules for testing the resilience of EU banks.

Also licking wounds from a secret ballot that tested friends and rivals in a race for lucrative spoils were the ex-communist countries of eastern Europe, which complain they host few of the EU's 40-odd agencies due to joining late.

Among winners were the EMA and its 900 staff, many of whom had said they might quit if posted to the poorer east, a threat that had raised concern about disruption in drug approvals.

It was the abstention of Slovakia, piqued by its capital Bratislava being narrowly knocked out of the EMA voting in the first round, which allowed Amsterdam to pull level with early leader Milan and tie the runoff at 13-13 - a result few had expected given that all 27 member states bar Britain had a vote.

Diplomats expressed astonishment that the EBA also went to a tie, obliging Matti Maasikas, the Estonian minister chairing the meeting, to dip his hand in for a second time to pick one of two balls from a fishbowl produced by officials for the day.

"It's like losing a final on penalties," Italy's EU affairs minister Sandro Gozi told reporters, adding that it had left a "bitter taste in the mouth" for an EMA bid that was not behind at any stage. He rejected, however, talk of "betrayal" among any allies who had promised Milan support before the secret ballot.

PHARMA WELCOME

The outcome was welcomed by European pharmaceuticals bodies.

"Businesses now need certainty," said Steve Bates, CEO of Britain’s BioIndustry Association. "We must now ensure Brexit does not disrupt the safe supply of vital medicines."

Dutch Foreign Minister Halbe Zijlstra and French European Affairs Minister Nathalie Loiseau - who both congratulated their Estonian counterpart on his "lucky" hand - told reporters both agencies would be ready to open their doors in Amsterdam and Paris on Monday, April 1, 2019, following Britain's formal withdrawal from the European Union at the start at the weekend.

Both dismissed suggestions that the process had been a slap to hopes of healing feelings of disgruntlement with the EU among increasingly nationalistic governments in parts of the east.

While "regional balance" had been among criteria that ministers were asked to observe in voting, so too was the ability to maintain the business continuity of agencies which already have about 1,000 employees between them in London.

In all, 19 cities had bid for the prestige and economic boost that the arrival of the EMA's 900 staff and many offices for international pharmaceuticals companies will bring.

Despite aggressive backroom dealmaking, the 27 EU states were keen to avoid any protracted and bruising dispute in public, hoping to preserving a sense of unity that has emerged - so far - in negotiations over Brexit with Britain.