'Chicharito' as he is known, scored 59 goals in his five-years with United.
Joint-chairman David Sullivan said: "We are delighted to welcome Javier as the latest fantastic addition to the West Ham United squad.
"We now have some fantastic options in attacking positions and, like all West Ham fans, I am looking forward to seeing Javier score goals in a claret and blue shirt next season."
Worth the wait.. #WelcomeChichapic.twitter.com/ZPJQLPnRpb
— West Ham United (@WestHamUtd) July 24, 2017