The Ghana international moved to the Liberty Stadium on a free transfer ahead of the 2015-16 season and was a star turn for a Swansea side that finished 12th.
Ayew and left-back Arthur Masuaku arrived at the London Stadium on Monday, following Ashley Fletcher, Havard Nordveit, Gokhan Tore, Sofiane Feghouli and Arthur Masuaku in joining the Hammers during the close-season.
West Ham co-chairman David Gold initially announced the signing, before West Ham’s official social media channels confirmed the move.
Swansea also acknowledged the departure of the forward, who will reunite with former Marseille team-mate Dimitri Payet in east London.
After joining Slaven Bilic’s side, Ayew told West Ham’s official website: “I am very proud and happy to be at this magnificent club.
“The club have a lot of ambition and have a great manager. They want to become a bigger club every year and with the new stadium and a new training ground, you can feel they are moving onto another level and I want to be part of this project.
“I want to train hard, do my job and show that I deserve to play for West Ham United. I want to give back to the manager and the fans the confidence they are showing me.”
Ayew scored 60 goals in 202 games for Marseille, winning the Coupe de la Ligue twice during his time at Stade Velodrome