Prime Minister Boris Johnson on Friday hailed "a new chapter" in Britain's history as he signed its divorce deal with the EU, clearing another hurdle ahead of the country's departure from the bloc next Friday.
Johnson signed the agreement in Downing Street in front of European and British Foreign Office officials who had brought it from Brussels.
EU chiefs Ursula von der Leyen and Charles Michel had put their names to the treaty at a ceremony held behind closed doors in the dead of night.
"The signing of the withdrawal agreement is a fantastic moment, which finally delivers the result of the 2016 referendum and brings to an end far too many years of argument and division," Johnson said in a statement.
"This signature heralds a new chapter in our nation's history," he added on Twitter.
The treaty will now return to Brussels, where the original will be kept in EU archives along with other international treaties, while three copies will be dispatched back to London.
On Wednesday next week, the text will go to the European Parliament for ratification and on Thursday diplomats from the EU member states will approve the deal in writing.
Then, on Friday, January 31, Britain spends its last day in the EU before leaving the bloc at 2300 GMT as clocks strike midnight in Brussels.
"Charles Michel and I have just signed the agreement on the withdrawal of the UK from the EU, opening the way for its ratification by the European Parliament," European Commission president Von der Leyen tweeted.
In a separate tweet, European Council president Michel said: "Things will inevitably change but our friendship will remain. We start a new chapter as partners and allies."
The former Belgian premier, whose council represents EU member governments, added, in French: "I'm keen to write this new page together."
In another move to prepare Brussels for relations with Britain as an outside power, the European Commission named an ambassador -- veteran diplomat Joao Vale de Almeida -- to London.
Johnson signed with a Parker fountain pen, as is traditional for ceremonial signings in Downing Street, with staff including the prime minister's chief Brexit negotiator David Frost present.
Earlier in Brussels, the signing was conducted before dawn in the European Council's headquarters, as chief EU Brexit negotiator Michel Barnier looked on.
No reporters or photographers were allowed to witness the low key ceremony, despite news agencies offering to organise a pool.
British voters backed leaving the European Union in a June 2016 referendum, and after lengthy negotiations and several delays Johnson's new government plans to "get Brexit done" next week.
Queen Elizabeth II gave her formal assent to the British withdrawal legislation on Thursday and the EU is now expected to complete the final formalities in the coming days.
Britain will leave the institutions of the union, reducing it to 27 member states, but the withdrawal agreement provides for an 11-month transition period until the end of the year.
During this time, Britain and the rest of the bloc will continue to apply the same rules of business to avoid economic disruption while officials try to negotiate a broader trade deal.
Most experts regard the idea that London and Brussels could agree a comprehensive free trade agreement in that time as ambitious.
But officials have expressed cautious optimism that some kind of agreement can be reached.
Formal trade talks are not expected to begin until the end of February or even March, and in the meantime Barnier has been in intensive talks with EU member states on his negotiating mandate.
After the transition, Britain wants the right to set its own rules in areas such as workers' rights and environmental standards.
But Brussels has warned that the more the UK diverges from EU standards, the less it will have unfettered access to Europe's huge single market.
And a comprehensive free trade agreement of the type the EU has signed with Canada could take years to negotiate.