Madrid announced the deal hours before the close of the summer transfer window on Monday.
The 26-year-old scored one goal for Mexico's during this summer's World Cup.
Hernandez, known by his nickname "Chicharito," played for Manchester for the past four seasons.
Madrid was routed 4-2 at Real Sociedad after leading by two goals on Sunday, increasing the pressure for the club to bulk up its squad after the exit of Angel Di Maria and Xabi Alonso.
All content copyright ©2014 Daily Journal, a division of Home News Enterprises unless otherwise noted.