West Ham did not disclose terms, but Ajax said the two clubs had agreed a transfer fee of €38 million ($41.90m), which could increase to €41m with add-ons.
"We're really pleased to add Edson to our squad," West Ham manager David Moyes said after his first signing of the summer transfer window.
"The midfield area was one we were especially keen to strengthen this summer, and Edson will complement the other options we have in that department.
"He's an experienced international player who has enjoyed great success for both club and country during his career to date."
The 25-year-old had twice helped Ajax to win the Eredivisie since his arrival in 2019, making 147 appearances and scoring 13 goals in all competitions.
Álvarez has been capped 69 times for Mexico, playing at the 2018 and 2022 World Cups.