A deal to bring Mexico's record goalscorer to London Stadium was hammered out several days ago.
Hernandez has penned a three-year contract and will fly out to Germany in the coming days to join up with West Ham coach Slaven Bilic and his new team-mates.
"I am very happy to join West Ham United. For me, the Premier League is the best league in the world and when the opportunity came, I was desperate to sign for this club," said Hernandez, who will sport the name Chicharito on his jersey.
The move follows the arrivals of England goalkeeper Joe Hart and Argentine defender Pablo Zabaleta from Man City, as well as Austrian winger Marko Arnautovic from Stoke in a club-record deal.
"He has a proven goalscoring record in the Premier League, La Liga and the Bundesliga, as well in the UEFA Champions League and at international level with Mexico," club joint-chairman David Sullivan said.
Hernandez, now 29, spent four seasons with United, where he scored 59 goals in 156 appearances, before going on loan to Real Madrid in the 2014/15 campaign.
The two-time Premier League winner left Old Trafford in August 2015 for Germany, where he was even more prolific, netting 39 times in 76 matches for Bayer Leverkusen.