The Everton manager was recommended by the outgoing Sir Alex Ferguson and his appointment has been unanimously approved by the United board.
Ferguson said: "When we discussed the candidates that we felt had the right attributes we unanimously agreed on David Moyes. David is a man of great integrity with a strong work ethic.
"I've admired his work for a long time and approached him as far back as 1998 to discuss the position of assistant manager here. He was a young man then at the start of his career and has since gone on to do a magnificent job at Everton. There is no question he has all the qualities we expect of a manager at this club."
Moyes met Everton chairman Bill Kenwright on Wednesday to tell him that he wished to leave, and the Toffees confirmed on Thursday that their manager of over 10 years is to go at the end of the season.
"The manager met chairman Bill Kenwright early yesterday evening and confirmed his desire to join Manchester United," Everton said in a statement on their website.
"The chairman, on behalf of the club, would like to place on record his thanks to David for the massive contribution he has made to Everton since his arrival in March 2002. He has been an outstanding manager."
Moyes leaves Everton after more than 11 years in charge, during which time he has consistently kept the club in the top half of the Premier League table - even achieving a fourth-place finish in the league in 2005 to earn a Champions League spot.
He has failed to win a trophy, however, with his only honour as a manager still being the League One title (then known as Division Two) with Preston North End back in 2000.
The Scot now has the huge task of replacing arguably the greatest manager in football's long history.
A six-year contract is a huge show of faith in Moyes and a clear signal that United are seeking continuity with the man to replace Ferguson, who will stay on as a member of the board.
Jose Mourinho had also been linked with the post but the Real Madrid coach's abrasive style had previously attracted criticism from United legend Sir Bobby Charlton.
Charlton said on Thursday: "I have always said that we wanted the next manager to be a genuine Manchester United man. In David Moyes, we have someone who understands the things that make this such a special club. We have secured a man who is committed to the long-term and will build teams for the future as well as now. Stability breeds success.
"David has tremendous strength of character and recognises the importance of bringing young players through and developing them alongside world class talent. At United, I think David will be able to express himself. I'm delighted he has accepted and I'm looking forward to working with him."
Moyes said: "It's a great honour to be asked to be the next manager of Manchester United. I am delighted that Sir Alex saw fit to recommend me for the job. I have great respect for everything he has done and for the football club.
"I know how hard it will be to follow the best manager ever, but the opportunity to manage Manchester United isn't something that comes around very often and I'm really looking forward to taking up the post next season.
"I have had a terrific job at Everton, with a tremendous chairman and board of directors and a great set of players. Between now and the end of the season, I will do everything in my power to make sure we finish as high as possible in the table.
"Everton's fantastic fans have played a big part in making my years at Goodison so enjoyable and I thank them wholeheartedly for the support they have given me and the players. Everton will be close to me for the rest of my life."