The 33-year-old, who has 88 international caps for his country, returns to the Premier League having previously played for Aston Villa between 2014 and 2016.
“I’m very happy to be here. I’m very excited and looking forward to achieving lots," said Sanchez, who becomes West Ham's ninth signing of the summer.
“I decided to come here because, first, it is the Premier League, second, it’s a beautiful club and the fans are always helping the club and, third, for me it’s an amazing opportunity and an amazing project the club are leading, being ambitious and keen to achieve good things.
“I’d like to thank all of the people, the whole club, for having me."
Director of Football Mario Husillos welcomed the midfielder's arrival, saying: “Carlos is a very experienced player whose career I have always followed closely and with admiration.
“He made a great impression for Elche in Spain when I was Sporting Director with Malaga, and came back to Spain last season on loan with Espanyol - plus of course he already has experience of England and the Premier League from his time with Aston Villa."
Sanchez joins the likes of Lucas Perez and Jack Wilshere at the London Stadium.
Join our new commenting forum
Join thought-provoking conversations, follow other Independent readers and see their replies