David, 28, joined United in 2011 and has made 367 appearances so far.
During his time with the club, he has won the Premier League, the FA Cup, the League Cup, the UEFA Europa League and the Community Shield.
Ole Gunnar Solskjaer said: “I am delighted that David has committed his long-term future to the club.
“Over recent years, David has proved himself to be the best in the world and a vital part of our plans as we look to take Manchester United back to where it belongs. David is a fantastic person and his outstanding quality provides the perfect base to our defense.