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 in the Premier League 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.