The 26-year-old scored 12 goals in 34 appearances for Swansea last season and now moves the Hammers for a fee in the region of £20.5-million, according to British media, which is a club-record fee.
West Ham had been unsuccessful in bids for Alexandre Lacazette, Michy Batshuayi and Carlos Bacca but have finally added another goalscorer to their ranks.
Manager Slaven Bilic will now have Ayew, Andy Carroll, Dimitri Payet, Manuel Lanzini and Sofiane Feghouli to choose from.
— West Ham United FC (@whufc_official) August 8, 2016
Ayew said on the club's official website: “I am very proud and happy to be at this magnificent Club. I am happy to be playing for these fans and I hope to make the people very happy here.
“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.”
Earlier in the day, West Ham secured the services of French left-back Arthur Masuaku on a four-year contract from Greek side Olympiacos.