Manchester United goalkeeper David De Gea has signed a new-four year contract with the club.
The 24-year-old Spain international almost joined Real Madrid on transfer deadline day, but the necessary paperwork was not submitted in time.
De Gea's previous contract was set to expire next summer, while his new deal includes an option for a further year.
"I'm looking forward to putting a difficult summer behind me and working hard," said De Gea.
|More from BBC Sport|
|Chelsea's Courtois set for knee operation||'Football needs Martial to be a hit'|
|Lawro's predictions v Mark Webber||Man Utd v Liverpool: Six great goals|
"I am delighted to be starting this new chapter in my United career.
"Manchester United is a special club and Old Trafford is an ideal place for me to continue to develop."
De Gea has not played for United this season as manager Louis van Gaal felt he could not focus amid interest from Real.
Had he not signed a new deal, De Gea could have opened talks in January about a free-transfer move to Madrid for next summer.
Van Gaal said he was "very pleased" the goalkeeper "will be part of the team for many years to come".
"David made a very important contribution to our performance last season and he has been the club's Player of the Year for the last two seasons," added the Dutchman.
De Gea has made 175 appearances for United since joining the club from Atletico Madrid in 2011 in an £18.9m deal.
He made several high-profile errors in his first few months in England, but has been in the Professional Footballers' Association Team of the Year in two of the past three seasons.
'The crazy world of football'
In his pre-match news conference before Saturday's home match against Liverpool (17:30 BST), Van Gaal was asked if two weeks ago he thought De Gea would stay.
"Yes, because it's a confirmation of what I also said about transfers being a process," he said. "I had hope.
"If Madrid paid the price and had the papers in order at the right time, he would have been sold, because I believe a player must want to play for a club.
"But I am delighted because he was my best player last year and it is a happy end.
"I thought only of what De Gea was suffering, but it is the world of football and it is a crazy world. I cannot change that crazy world."
When asked if De Gea would play against Liverpool, Van Gaal said: "You shall see - you never know. We have to judge him in training.
"It's logical that his head is now empty and he can concentrate and focus on the match.
"That is a big change from three or four weeks before, so I hope I can see that and give him his first start."
De Gea feels he is ready after playing for Spain in their Euro 2016 qualifier against Macedonia on 8 September.
"I feel ready and 100% fit," he said.
"It is a perfect moment to come back and at Old Trafford, with the fans and against Liverpool, one of the biggest games in the world and I know the fans will love it if we win the game."
BBC Sport's Simon Stone:
"The deal De Gea has signed is the same one that was on table in the summer. When the move to Real Madrid fell through, United approached the De Gea camp to ask if he would sign.
"It has been stressed to De Gea by various people, including manager Louis van Gaal, that he is an important part of the club's plans.
"United are not saying if there is a release fee in the contract but point out if Real wanted De Gea at the end of the season they would have to pay, whereas previously they would have got him for nothing.
"They are stressing the deal has been done in good faith."
Marca football writer Juan Castro:
"For the fans, it's surprising - a player who just 12 days ago was about to sign for Real Madrid is now renewing his contract with Manchester United.
"It's difficult to say right now if Real will try to sign him again. After what happened in the last minute of deadline day, everything is possible.
"Real president Florentino Perez still wants De Gea, but now he has another enemy - Manchester United - even bigger than before. This enemy is bigger and bigger every day and Florentino Perez knows that."