The 25-year-old will join the east London side on July 1 when his existing contract expires.
Diame is West Ham's third signing since they secured promotion but the first outfield player.
"His potential is really good and he's ready to go and compete in the first team straight away as he's had three years in the Premier League already," said Hammers manager Sam Allardyce on the club website.
"He's 25 and can only get better and I hope he can go on to prove that to me and all of the West Ham United fans. He will be a very exciting addition to the squad."
West Ham's other two signings are Irish goalkeeper Stephen Henderson, whose arrival on loan from Portsmouth has become permanent, and former Finland international goalkeeper Jussi Jaaskelainen from relegated Bolton Wanderers.
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.