The 23-year-old versatile left-back spent two seasons at the Etihad Stadium after signing in the summer of 2022 from Belgian outfit Anderlecht.
During that time, Gomez struggled to establish himself as a first-team regular under manager Pep Guardiola and only made a total of 38 appearances across all competitions.
The Spaniard played 15 times last season, but was reduced to just four starts and only 48 minutes of Premier League football, with both Josko Gvardiol and Nathan Ake preferred at left-back.
Gomez was nevertheless part of the Man City squad that won a historic treble - Premier League, FA Cup and Champions League - in 2022-23, followed by the UEFA Super Cup, FIFA Club World Cup and Premier League across the 2023-24 campaign.
Gomez joins Real Sociedad on six-year deal
The defender will now embark on a fresh challenge back in his homeland with La Liga side Real Sociedad, who finished sixth in the Spanish top-flight table last season.
According to journalist Fabrizio Romano, Man City will receive €10m (£8.4m) including add-ons from Sociedad for the transfer of Gomez, and the Citizens have also included 30% sell-on clause in the deal.
Gomez, who has put pen to paper on a six-year contract at Sociedad until the summer of 2030, has thanked everyone associated with Man City for his time at the club, but believes that now is the right time to take the next step in his career.
"It's time to leave Manchester City but I'd like to thank everyone at the CFA for their support and guidance during my time at the club," Gomez told mancity.com.
Begiristain has "no doubt" Gomez will "make his mark" at Sociedad
"Being part of such a talented, ambitious and successful squad was a true honour and winning a host of major trophies, including the treble, is something I will never forget and will always look back fondly on.
"I am excited for this new adventure but I wish Pep Guardiola and the players every success in the future."
Man City's director of football Txiki Begiristain added: "I'd like to thank Sergio for his time at Manchester City. He is an impressive young footballer, with a good attitude and strong application, who I have no doubt will make his mark and excel in the coming years. We wish him the best for the future."
Gomez becomes Sociedad's first signing of the summer transfer window and will be hoping to make his competitive debut for Imanol Alguacil's side when they face Rayo Vallecano in their opening La Liga fixture of the 2024-25 season on August 18.