Sanchez returns to the Premier League after spending two seasons with Aston Villa between 2014 and 2016.
He becomes West Ham's ninth summer signing and second of transfer deadline day, after striker Lucas Perez joined from Arsenal.
“I’m very happy to be here. I’m very excited and looking forward to achieving lots," Sanchez said in a club release.
“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."
Sanchez has been capped 88 times by Colombia and has featured at two World Cups, including this summer's tournament in Russia.
“Carlos is a very experienced player whose career I have always followed closely and with admiration," West Ham director of football Mario Husillos said.
“He has great quality as a holding midfielder. He can also cover other positions but it is as a defensive midfielder that he really excels."