Baku, February 1 AZERTAC
The 45-year-old, currently in charge at Bayern Munich, will replace Manuel Pellegrini, who will leave on 30 June.
A statement from City said Chilean Pellegrini, 62, was "fully supportive" of the announcement being made.
The club said negotiations with former Barcelona coach Guardiola had been "a recommencement of discussions that were curtailed in 2012".
Roberto Mancini was City boss at the time, and led them to the domestic title that year.
Pellegrini succeeded the Italian in 2013 and took the club to a Premier League and League Cup double the following season.
He has won 64 of his 99 Premier League games as a manager, a record only eclipsed by Jose Mourinho, who won 73 of his opening 99 league matches as Chelsea boss.
City could yet win four trophies under Pellegrini this season.
They are already through to the final of the League Cup and are second in the league behind Leicester City.