Gundogan's contract at the Etihad Stadium expired this month, and despite Pep Guardiola's desire to keep him at the club, reports last week claimed that he had decided to join Barcelona.
Both the Catalan club and Man City have now confirmed that deal, with Gundogan putting pen to paper on a two-year contract at Camp Nou, with the option of a further year beyond that.
The 32-year-old's contract in Catalonia includes a €400m (£341.9m) release clause.
Gundogan becomes Barcelona's first signing of the summer and could make his competitive debut for the club when they face Getafe on the opening weekend of the 2023-24 La Liga season, which Barca will enter as defending champions.
Gundogan was Guardiola's first signing as Man City boss and went on to make 304 appearances for the club during his seven-year stay, scoring 60 goals.
The Germany international helped the Citizens to 14 trophies during his time at the Etihad, including five Premier League titles, two FA Cups, four EFL Cups and the Champions League.
Gundogan took over as club captain from Fernandinho last summer and led City to a historic treble during his only season with the armband, winning the Premier League, FA Cup and Champions League in 2022-23.
"For me it has been a total privilege and pleasure to be part of Manchester City for the last seven years," Gundogan told the Man City website.
"Manchester has been my home and I have felt part of a very special family at City. I have been lucky to have experienced so many unforgettable moments in my time here and to have been captain for this extra special season has been the greatest experience of my career.
"First, I would like to thank Pep. To have been able to play under and learn from him for so long has been something I will never forget. I would also like to thank all my teammates - past and present - who have all played such a special part in making my time here so amazing.
"Finally, I would like to thank the incredible City fans. They have supported me from the moment I arrived, and I owe them all so much for their support. This club made me realise all my dreams and I will forever be thankful for this opportunity.
"I will carry City always in my heart. Once a blue, always a blue."
Man City director of football Txiki Begiristain added: "Ilkay has been a wonderful servant for Manchester City, and he leaves our club on a very special high having captained us to a historic treble.
"He has played a huge part in the successes we have enjoyed in recent seasons and Ilkay's intelligence, leadership and commitment to the club - both on and off the field - has been an inspiration to everyone.
"Ilkay has truly cemented his place in the history of Manchester City and we all wish him well in the next chapter of his career. And he leaves us knowing that he will always be welcomed at this football club."
Gundogan played a particularly pivotal role in the closing stages of Man City's treble-winning campaign, including Premier League braces against both Leeds United and Everton.
The midfielder helped himself to another two-goal haul in the FA Cup final against Manchester United, the first of which was the fastest goal in FA Cup final history.
Gundogan also memorably scored twice on the final day of the 2021-22 Premier League season as Man City overturned a 2-0 deficit to beat Aston Villa 3-2 and win the title.
The German's best scoring season saw him net 17 times in 46 games across all competitions in 2020-21.