Beckham's future had been the subject of intense speculation since helping United win the Premier League title the previous month, with a number of top clubs interested in signing the then England captain.
Barcelona had seemingly stolen the initiative over their fierce Spanish rivals but it was Madrid, who initially denied they wanted to sign Beckham, who swooped in late to lure him to the Bernabeu to play alongside superstars Zinedine Zidane, Luis Figo, Ronaldo and Raul.
United confirmed in a statement: "David Beckham has agreed personal terms with Real Madrid and expects to sign his new contract with the club on completion.
"The deal is expected to be completed in July, conditional upon approval by the boards of Manchester United and Real Madrid, and on the provision of satisfactory payment guarantees.
"The proceeds of the sale will be used to support Manchester United's business development, including continuing to maintain its playing success at the highest levels of the game."
Beckham progressed through the academy at United and made 394 appearances for the club, scoring 85 goals and winning six Premier League titles, two FA Cups and the 1999 Champions League.
He clinched one LaLiga crown in Madrid, in the final season of his four-year stay, before going on to play for the Los Angeles Galaxy, AC Milan and Paris St Germain.