Gomez, 25, has made 142 appearances for Liverpool since joining them from Charlton Athletic in 2015, helping them to lift the Premier League, the FA Cup and the Champions League among other major honours.
But the England international has also endured torrid luck with injuries, missing the majority of the 2020-21 season with a serious knee problem.
But the defender has now committed his future to Liverpool and said in a statement that his "best years" are ahead of him.
"It's obviously a special moment for me and my family," Gomez told the official club website. "Another one that you dream of as a kid and one I don't take for granted.
"It is an unbelievable place to be; in my eyes, probably one of the best -- if not the best -- clubs in the world at the minute. The opportunity to extend my stay here was an easy decision to make, really.
"Obviously, I have been here quite a while now, but in the grand scheme of things I still feel young and, like you say, the best years are ahead of me. I have got more to learn and the time to do that.
"I think I have the platform here to do it with the manager and the coaching staff around me and my teammates, to make sure the best years are ahead."
Gomez has also made 11 appearances for England since he arrived at Liverpool, although his last cap came two years ago.
"I think as a group, the sky is the limit," Gomez added. "We want to go one, if not two, better than last season and aim for it all.
"We definitely have the ability to do that and the belief is there, it's just about us taking it one game at a time, like we did last season, and just being true to ourselves, playing the way we play under the gaffer's guidance."