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.
“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.
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.”