The 31-year-old full-back will link up with his new club after his current deal with Ukrainian champions Shakhtar Donetsk expires on July 1.
Rat has spent the last 10 years in Ukraine, winning 15 trophies in total and has 88 international caps.
"I'm hugely happy that we've got a player of his experience and his character," West Ham manager Sam Allardyce said on the club website.
"He's been playing Champions League football this year and at the highest level for many years. Shakhtar had offered him a very good contract, but his ambition was to come and try his abilities and skills in England.
"When you hear somebody speak so positively about that, then you know they've got the mental character that's needed to do well in this division."
Next up for the East London side could be Carroll, as Liverpool are reported to have accepted a bid in the region of £15 million for the England international.
It is understood Liverpool agreed several weeks ago to accept a fee of £15million, rising with various add-ons, to get the 24-year-old striker off their wage bill.
With the Hammers willing to pay the asking price for a player that cost £35million when joining the Reds from Newcastle in January 2011, the only barrier to the transfer is Carroll himself, who has spoken fondly of his season-long loan at Upton Park.
The striker said in an interview with the West Ham website: "I have enjoyed every minute of being here.
“I have just tried to play my best in every match, score goals and keep myself fit once I got back from the injuries I had and then push on from there.
“The West Ham fans have been brilliant – they were chanting my name all through the match (against Reading), they never stopped and I thank them for the way they have supported me here from the moment I arrived.”
Meanwhile, Carlton Cole looks set to leave West Ham after saying his goodbye's to the fans on Twitter.