Los Blancos made multiple bids for Mbappe in 2021, but all were turned down by PSG.
Madrid had been widely expected to sign Mbappe as a free agent, with reports earlier this month claiming the deal was all but done.
Mbappe was voted Ligue 1 player of the season for a third successive time last week, before declaring at the Union Nationale des Footballeurs Professionnels award ceremony in Paris that he would resolve his future before France's UEFA Nations League fixtures in June.
However, in an extraordinary twist, reports circulated that Mbappe had in fact decided to take up PSG's offer of a new contract and remain in the French capital.
His mother and agent confirmed on Saturday (AEST) that agreements had been reached with both clubs and, on Sunday (AEST) before PSG's season-ending game against Metz, it was confirmed Mbappe would be staying put and had signed a three-year deal.
Mbappe was paraded on the pitch before the game at Parc des Princes, with a "2025" shirt.
The 23-year-old has enjoyed another stellar campaign, scoring 36 goals and providing 21 assists across all competitions for PSG.
Mbappe is the club's second-highest goalscorer, behind Edinson Cavani, having overtaken Zlatan Ibrahimovic when he netted for the 157th time in a PSG shirt earlier this season.
Despite its wealth, PSG keeping hold of Mbappe is a huge coup for the Ligue 1 champion.
PSG's efforts to win the UEFA Champions League again fell short this term, despite Mbappe's sensational performance over two legs against Madrid, but with the forward still on board, alongside Lionel Messi and Neymar, European success will again be the priority target in 2022-2023.