Ayew, 26, signed for Swansea on a free transfer from Marseille in June 2015 and scored 12 goals in his first Premier League season.
The Ghana international won the BBC African Player of the Year in 2011 and signs a four-year deal to become West Ham’s record signing.
“The club have a lot of ambition and have a great manager,” said Ayew.
“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 on to another level and I want to be part of this project.”
He is the club’s fifth signing this summer, as they prepare for their first season playing in the London Stadium.
Sofiane Feghouli, Havard Nordtveit and Ashley Fletcher signed on free transfers from Valencia, Borussia Monchengladbach and Manchester United respectively.
On Monday, the Hammers also completed the transfer of French left-back Arthur Masuaku from Olympiakos in a deal worth a reported £6m.
The £20.5m fee for Ayew eclipses the £15m West Ham paid Liverpool for England striker Andy Carroll in June 2013.
— André Ayew (@AyewAndre) August 8, 2016