Moyes joins the club following the departure of Slaven Bilic, with whom the Hammers parted company on Monday after Saturday’s 4-1 home defeat by Liverpool left them 18th in the Premier League table.
West Ham will be the fourth club managed by Moyes in the PL, and his first match as manager, at Watford on Sunday 19 November, will also be his 500th in the competition.
“We need somebody with experience, knowledge of the Premier League and the players in it, and we believe David is the right man to turn things around," joint-chairman David Sullivan told West Ham's official website.
"He is highly regarded and respected within the game, and will bring fresh ideas, organisation and enthusiasm."
The Scot, 54, was most recently in the Premier League with Sunderland last season. Before that he had a short spell with Manchester United, having previously spent 11 seasons at Everton, guiding the Toffees to what remains their best PL finish, fourth in 2004/05.