City will pay an initial £28.5m for the Argentina international, who was named in La Liga's 2014-15 team of the season and played in the Copa America final.
"To be here inside a club that looks so wonderful from the outside is a dream," said the 27-year-old ex-Porto player.
City manager Manuel Pellegrini said: "He's strong, he's excellent in the tackle and he's very good technically."
The Chilean added: "He is an established international for one of the best nations in world football and I have no doubt that he has the right mentality to fit into a squad where he will find many familiar faces, including Eliaquim [Mangala] and Fernando, who he played alongside in Portugal."
Former Argentina coach Diego Maradona gave Otamendi his first senior cap when he was called up for the 2010 World Cup qualifier against Panama.
He was a member of the squad that qualified for the tournament in South Africa, but was dropped by coach Alejandro Sabella for the World Cup in Brazil four years later.
Otamendi is City's third major summer signing following the arrival of England internationals Raheem Sterling and Fabian Delph.
Find all the latest football transfers on our dedicated page.
Manchester City have signed defender Nicolas Otamendi from Valencia on a five-year deal worth £32m.