The European champions have an option to buy the 26-year-old Hernandez, who is known as “Chicharito” (little pea) and will provide backup for Real’s first-choice striker Karim Benzema, a France international.
Hernandez, valued at 14 million euros (11.08 million pounds) on website transfermarkt佛山桑拿,, passed a medical and was presented at the club’s Bernabeu stadium.
He is surplus to requirements at United as the English Premier League club have agreed to take Colombia striker Radamel Falcao on loan from AS Monaco.
“I don’t think there is a player in the world who would not say this is a dream, it would be a lie,” a beaming Hernandez told a news conference.
“I am coming to give my all so that this club can be more successful than it already is,” he added.
“I will give everything. I hope to contribute my grain of sand so that many trophies continue to come.”
Hernandez joined United from hometown side Guadalajara in July 2010 but after a fine debut season, when he scored 20 goals in all competitions, he has played mostly as a substitute.
He helped Mexico reach the last 16 of the World Cup in Brazil, scoring in the 3-1 group-stage win over Croatia.
Real, who have also bought Colombia playmaker James Rodriguez and Germany midfielder Toni Kroos in the current transfer window, suffered a surprise 4-2 La Liga reverse at Real Sociedad on Sunday.
Their next outing is at home to champions Atletico Madrid on Sept. 13, when Hernandez could make his debut.
Asked whether he would accept playing mainly as a substitute, Hernandez said he had come to Real to be “part of the squad”.
“I see it as a great opportunity, to do what I like most which is playing football,” he told reporters.
“The only thing I have in my heart is that I am grateful to those who have given me this chance.
“To be alongside the best players in the world and be able to develop and give everything to the club. I know that here 100 percent is demanded.”
Hernandez is the son of namesake Javier Hernandez, a Mexico striker who featured at the 1986 World Cup and was nicknamed “Chicharo”, or “pea”, because of his green eyes.
(Reporting by Iain Rogers, editing by Justin Palmer/Rex Gowar)