The Mexican, 23, who signed from Chivas de Guadalajara in July 2010, scored 23 goals in his first season at the club.
United boss Sir Alex Ferguson said: "The last player I remember making an impact as quickly is Ole Gunnar Solskjaer. Javier reminds me of Ole."
Hernandez said: "Playing for Manchester United has been a dream come true."
He added: "I never expected my first year to go so well and I'm delighted to commit my future to United.
"To win a title and appear in a Champions League final was fantastic. I'm looking forward to helping my team-mates as we bid to win more trophies for this great club."
The Mexico international was on the bench for United's 6-1 drubbing by neighbours Manchester City on Sunday but came on after 65 minutes.
He missed the start of the season after suffering concussion on United's pre-season tour of the United States.
Media playback is not supported on this device
He has recently been linked with a move to Real Madrid and United have acted to tie him up on a long-term deal.
Ferguson added: "His talent for creating space in the box and his finishing ability mark him out as a natural goalscorer.
"Off the pitch, he is a pleasure to manage.  He works very hard and is a popular member of the squad."
For the latest updates and reaction to this story, read Sportsday Live. Have your say on Twitter via the hashtag #bbcsportsday.
Manchester United striker Javier Hernandez has signed a new five-year contract to keep him at Old Trafford until 2016.