The 30-year-old’s deal includes an option of a further two and the striker joins the Hammers for an undisclosed fee.
Jelavic has scored goals for Everton and Hull City in the Premier League over the last three years.
He told West Ham’s official website: “I am very excited to be signing for West Ham United, especially as it is a big Club and I didn’t know until a couple of days ago that I would have the opportunity to come here.
“Of course it is always a target to play in the Premier League, so when I found out that West Ham wanted me there was no doubt that I wanted to come here.
“I’ve played for Slaven before for the Croatia national team and he is a great manager and a great man. I am really happy and delighted to be working with him and all his staff again.
“I’ll be joining a team that’s on a high after the result on Saturday.”