Gomez is one of Liverpool's longest serving players, having joined from Charlton Athletic in the summer of 2015.
The 25-year-old returned from a long-term knee injury last season to make 21 appearances in all competitions but only eight of them came in the Premier League.
The versatile defender, who is capable of playing at right back and central defense was reportedly attracting interest from the likes of Aston Villa and Newcastle United but has opted to continue his journey with Jurgen Klopp's side.
Gomez has made 142 appearances across all competitions since joining Liverpool and has helped them win the Premier League, Champions League, UEFA Super Cup, FA Cup, Carabao Cup and FIFA Club World Cup.
"It's obviously a special moment for me and my family. Another one that you dream of as a kid and one I don't take for granted," Gomez told liverpoolfc.com after signing his new deal.
"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."
Klopp added:"Joe is an outstanding talent. He is also an outstanding defender and an outstanding human being.
"He has so many qualities, I could talk about them all day, so knowing that he will continue his journey with us is a massive boost – one that everyone who loves Liverpool FC and cares about its present and future should be unbelievably happy about.
"One of the many wonderful things about Joe is he has experience and youth – that's not a bad combination. He has not long turned 25 but he was at the club before I was and I think after Hendo and Millie he is our longest-serving player. Incredible. But the best thing of all is that his best years are still to come and I could not be happier that this will happen with us.
"In terms of right now, Joe is in phenomenal shape. We had a few weeks off and when I returned to AXA I saw him and my first thought was 'Wow!' Physically, he is in such a good place and now all he needs is a good pre-season and the rhythm that comes from this. Everything else is in place and I could not be happier that he will be staying with us for even longer."