Michail Antonio put West Ham ahead in the 23rd minute with a right-foot shot after Winston Reid headed on a corner.
Giannelli Imbula equalised with a low strike from outside the penalty area and Diouf struck two minutes from time with a fine header to lift Stoke to ninth in the standings.
Defeat ended West Ham's hopes of a top-six finish.
News that makes sense
Your trusted source for staying up-to-date with the world around you. Get free daily news updates and analysis, straight to your inbox.
(Reporting by Ed Osmond; Editing by Toby Davis)
