Chief EU negotiator Michel Barnier and his British counterpart David Davis said the agreement, which European leaders will sign at a summit this week, was a "decisive step".
The two sides also agreed on a "backstop" solution for the thorny issue of the future of the Irish border, just weeks after Prime Minister Theresa May said no British premier could ever accept such an idea.
The deal, secured after what Frenchman Barnier called an "intensive" weekend of talks in Brussels, paves the way for talks on a future trade deal to start next month and sent the pound surging.
"We were able this morning to agree, after all those days and nights of hard work, on a large part of what will be an international agreement for the orderly withdrawal of the United Kingdom," Barnier told a press conference with Davis.
The transition will begin on Brexit day -- March 29, 2019 -- and last until December 31, 2020. During that period, Britain "will no longer participate in the European Union decision-making process," Barnier said.
"Nevertheless, it will preserve the benefits, the advantages of the single market and the customs union... and will therefore be required to respect all the European rules just like all member states do."
- 'Certainty' for the future -
Standing against a backdrop of British and EU flags, Davis told the news conference that the 21-month transition "gives the certainty demanded by businesses and citizens across Britain and the European Union."
Firms across Europe that need to plan their business years in the future have been clamouring for both sides to reach a deal to avoid a cliff-edge departure, and Davis said it was "near enough" the full two years Britain had demanded.
Davis said Britain would be able to sign trade deals with other countries during the transition, despite EU rules saying it should not be while subject to the bloc's customs rules.
He added that Britain would now allow EU citizens moving to Britain during the transition phase to have the same rights to work and live in the country as those who arrived before, a policy London previously rejected.
May, who reached an outline deal on the divorce with the EU in December, said in a statement that the deal showed that "we can get an arrangement for the future which will be in the interests" of both sides.
Both sides wanted the transition deal in place so that it could be signed off by EU leaders at a Brussels summit on Friday, allowing the unlocking of talks on the future British-EU relationship in April.
- 'Backstop' solution -
Britain meanwhile agreed to the EU's "backstop" plan for the status of the Irish border, under which British-ruled Northern Ireland would remain part of the EU's customs union if there is no better idea.
The thorny issue will, however, require further talks to be fully resolved, the two sides said.
The EU insists that any divorce deal must ensure there is no "hard border" between EU member Ireland and Northern Ireland, saying it could compromise the 1998 peace accord that ended decades of sectarian violence in the British province.
The move appeared to be a climbdown for May, who insisted in February that "no UK prime minister could ever agree" to the plan as it would threaten Britain's constitutional integrity.
The pro-British party in Northern Ireland that props up her government has previously deemed the backstop arrangement "unacceptable".
Davis however denied that Britain had backed down, saying it was still pushing for a solution as part of a trade deal which would mean there was no need for the backstop.
Irish Foreign Minister Simon Coveney, who met Barnier in Brussels, said on Twitter on Monday that "Brexit negotiations are moving forward."
Sterling climbed to $1.41 against the dollar and reached 87 pence against the euro on news of the deal.
London and Brussels had already drawn closer in recent days over the poisoning of a Russian ex-spy, with EU foreign ministers on Monday offering "unqualified solidarity" over the attempted murder of Sergei Skripal.//AFP