The 22-year-old attracted a host of interest from the Premier League this month after entering the final six months of his contract at Elland Road.
Everton looked to have got there first after agreeing a transfer fee with Leeds, but the Hammers swooped for right-back on Monday and offered him a more lucrative deal.
And now West Ham have announced the transfer, which is thought to have cost them just £3.7million.
A club statement said: "The Essex-born player joins the Hammers, who have fought off strong competition to capture the promising 22-year-old, on a four-and-a-half year contract."
While Leeds said on his departure: "Leeds United can confirm that Sam Byram has joined West Ham United for an undisclosed fee.
"The 22-year-old has signed a four-and-a-half-year deal with the Hammers and leaves with the club’s best wishes and appreciation of his efforts during his time at Leeds United."
The Thorp Arch academy product was subject to a number of new deals to stay at Leeds before the January window opened, but they were all rejected by his agent Colin Pomford.
David Sullivan revealed West Ham wanted to sign Byram at the end of the season, but realised they had to move quickly after Everton's bid was accepted.
Sam Byram has three Championship goals to his name this season
"We hoped to sign Sam Byram in the summer when he was out of contract at Leeds," the Hammers chief said.
"In the last few days, it looked like he was going to Everton, so we realised it was now or never and had to pitch in to sign him.
"Hopefully that will go through in the next 24 hours. Everything has been agreed with the player and the club.
"I wouldn't normally say this but the Leeds chairman has made it public, because I think it's wrong to mention what you're doing until it's done. But if they're happy to mention it, so are we."
Invalid email
We use your sign-up to provide content in ways you've consented to and to improve our understanding of you. This may include adverts from us and 3rd parties based on our understanding. You can unsubscribe at any time. Read our Privacy Policy