The experienced left-back will join the Hammers on an initial one-year deal after his contract with Ukrainian champions Shakhtar Donetsk expires on 1 July.
Rat has spent the last 10 years in the Ukraine, winning 15 trophies, and has 88 international caps.
"I'm hugely happy that we've got a player of his experience and character," manager Sam Allardyce told West Ham's official 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.
"We certainly know he's got the ability and he's at an age where he's still capable of producing at 31. He speaks perfect English, which he taught himself, and that shows the discipline and character of the man.
"Discipline, character and ability are the three big things in the Premier League and, with a little bit of adjusting, we'll see him early on in the season giving hopefully his best performances for West Ham."