Britain's departure from the European Union has been set in law as the bloc's parliament voted to ratify the divorce papers.

After half a century of sometimes awkward membership and three years of tense withdrawal talks, the UK will leave the EU at 11pm Irish time on Friday.

MEPs voted by 621 votes to 49 to pass the withdrawal agreement, which sees Britain leave the EU institutions but remain under most EU rules during a transition until the end of the year.

Following the vote, MEPs burst into a chorus of "Auld Lang Syne", a traditional Scottish song of farewell.

The Brexit Withdrawal Agreement was passed by 621 to 49

The transition will see British Prime Minister Boris Johnson's government try to negotiate an ambitious - unprecedented in the timeframe - free trade agreement with his 27 former partners remaining in the bloc.

"Only in the agony of parting do we look into the depth of love," EU Commission president Ursula von der Leyen told the chamber, quoting British author George Eliot.

"We will always love you and we will never be far. Long live Europe."

In other words, as French Foreign Minister Jean-Yves Le Drian said: "The hardest part lies ahead... we're going to get down to brass tacks now."

In the Brussels parliament, many MEPs made it clear that they were voting for the withdrawal deal not out of any support for Brexit, but to avoid the disruption of a chaotic no-deal divorce.

Some expressed real anguish and regret, and pointed to Britain's role not only in the development of the European unification project but also to its historic battles against tyranny on the continent.

"If we could stop Brexit by voting 'no' today I would be the first to recommend it," former Belgian premier and chairman of the parliament's Brexit steering group Guy Verhofstadt said.

"It is indeed a sad issue," he said, turning to the World Wars of the first half of the last century. "We're sad to see a country leaving that twice liberated us, twice has given its blood to liberate Europe."

The day began with Britain's permanent representative to the EU Tim Barrow - from Saturday to be its ambassador - handing back the withdrawal agreement signed by Mr Johnson, to be stored in Brussels.

"This step ensures that the UK has fulfilled its legal obligations regarding our exit from the EU," the British mission said.

But it was still an emotional day in the European Parliament in Brussels, steeped in a mixture of nostalgia, political carnival and historical metaphor.

Nigel Farage, veteran MEP and leader of Britain's Brexit Party, was in triumphant mood after two decades as a thorn in Brussels' side.

After his final speech in parliament, in which he described Brexit as a victory for populism over "globalism", Mr Farage and his MEPs brandished British flags, in contravention of the rules, then left.

"We're going to wave you goodbye," he declared, as deputy speaker Mairead McGuinness cut his microphone.

"If you disobey the rules, you'll get cut off," she retorted.

At an earlier news conference, Mr Farage said he had loved playing the "pantomime villain" in the Strasbourg assembly, feeding opposition to Europe at home with theatrical YouTube clips.

But he insisted on the seriousness of Brexit, comparing its significance to king Henry VIII taking Britain out of the Catholic church in 1534.

"He took us out of the Church of Rome, and we are leaving the Treaty of Rome," he said, referring to the EU's 1957 founding document.

Later in the day, Mr Farage's fellow MEPs gathered for the historic vote to incorporate the withdrawal agreement into EU law.

This was the last legislative act of the 73 remaining British MEPs, and departure was hard for some.

Iratxe Garcia Perez, the Spanish leader of the Socialist group, choked back tears as she said farewell to her British Labour Party comrades.

Read more:

Britain will not align with EU rules after Brexit - Patel

Frictionless trade post Brexit is impossible - Barnier

More Brexit stories

After Brexit the United Kingdom will be what the EU calls a "third country", outside the union, but the political and economic drama will continue.

Britain and Europe will apply EU rules on trade and free movement of citizens until the end of the year, while negotiating a free trade agreement.

In the face of scepticism in EU capitals, Mr Johnson insists he is optimistic that a comprehensive free trade deal can be done before the next cliff-edge.

But negotiations between the world's sixth biggest economy and a 27-nation single market with a population of 450 million will be tricky.

Fishing rights, residency and working rights for citizens, tariff free trade, access to Europe for Britain's huge services sector: all will be on the table.

"We are considering a free trade agreement with zero tariffs and zero quotas. This would be unique. No other free trade agreement offers such access to our single market," Ms von der Leyen said.

"But the pre-condition is that European and British businesses continue to compete on a level playing field. We will not expose our companies to unfair competition," she warned, to applause.

Mr Johnson's government hopes more trade with the United States and Asian powers can help offset the costs of Brexit.

But the British premier was facing difficult talks today with US President Donald Trump's secretary of state Mike Pompeo.

Mr Trump backed Brexit, but Washington opposed Mr Johnson's decision to allow Chinese telecoms giant to work on Britain's 5G telecoms network despite security fears.