Ayew signed for Swansea on a free transfer from Marseille in June 2015 and scored 12 goals in his first Premier League season.
And the 26-year-old has signed a three-year deal with the Olympic Stadium.
Ayew in a statement after the transfer aid: “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.”
He added: “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 becomes West Ham’s sixth signing of the summer and he will be back in european football competition as West Ham will compete in the Europa League.