Mata, 25, has 32 caps for the Spanish national team and has played 135 times for Chelsea, scoring 32 goals since signing from Valencia in 2011
Juan Mata said: "I am thrilled to be joining United. I have enjoyed some very happy years at Chelsea but the time has come for a new challenge. United is the perfect place for me and I am excited at the chance I have to be part of the next phase in the club's history.
"Chelsea is a top club and I have many friends there but you cannot turn down the chance to join Manchester United. I look forward to helping the manager and the team be successful in the coming years."
David Moyes said: "Juan is one of the finest playmakers in the game today and it's a real pleasure to have secured his signature. He's been instrumental in Chelsea's recent success, with a notable 28 assists and 32 goals in his last two Premier League seasons.
"I have been impressed with the excitement he has shown to be part of the new Manchester United. I know our fans have admired Juan for some time now – he has always played well against us – and I know they will be delighted to see him in the red of United, starting on Tuesday."