The former Everton and Manchester United boss replaces Slaven Bilic, who was sacked on Monday with the Hammers in the relegation zone.
Moyes has been out of work since May, when he resigned as Sunderland manager after the club’s relegation to the Championship.
West Ham joint chairman David Sullivan said the 54-year-old Scot is “the right man to turn things around”.
He added: “We need somebody with experience, knowledge of the Premier League and the players in it, and we believe David can get the best out of the players.
“He is highly regarded and respected within the game and will bring fresh ideas, organisation and enthusiasm.
“He proved with Everton that he has great qualities and we feel that West Ham United is a club that will give David the platform to display those qualities again.”
Moyes’ first game in charge will be at Watford in the Premier League on 19 November.
He added: “I’m really looking forward to meeting the supporters, being in the stadium with them. I’m looking forward to them getting right behind the team and my team also.
“We need their support, we need everybody with us.”