Earlier, Nice briefly cut the gap with a 2-0 win at Metz. But three of the teams just behind them lost.
Messi, returning from Covid, started on the bench while Kylian Mbappe returned to the starting lineup after a groin strain while Ramos made only his second league start of the season.
Marco Verratti put PSG ahead in the final minute of a sluggish first half, drilling home his first Ligue 1 goal since May 2017.
PSG upped the tempo after the break.
Ramos, who arrived from Real in the summer, scored his first goal for the club. The central defender reacted quickest to a loose ball from a PSG corner. After his first shot was parried by Predrag Rajkovic, the Spaniard reacted fastest again to slam home the rebound.
“I am happy to have played 90 minutes and I am personally happy because it is my first goal with PSG, I hope there will be many more,” said Ramos.
“It’s been three weeks since I started playing normally with the group,” he said. “We have the cup, we have the league, we have the Champions League, this is the best time to arrive in shape.”
That goal brought Ramos level with Messi on one league goal this season, it also acted as the cue for Messi to come on.
In the 67th minute, Messi set up Verratti for a shot that deflected off two defenders and into the top corner.
Danilo Pereira added a fourth as PSG matched their biggest league win of the season.
Earlier, Khephren Thuram’s goal set up a precious 2-0 away win for Nice as they saw off strugglers Metz to move back up to second place.
Khephren, the 20-year-old son of World Cup winner Lilian, opened the scoring in the 58th minute while a late spot-kick from Amine Gouiri completed the victory with a cheeky Panenka.
The three points lift Nice above their bitter south coast rivals Marseille, who are two points behind in third with a game in hand.
“We are still too far behind (PSG) to think about top spot. I’m more concerned by what’s coming up behind us,” said Nice coach Christophe Galtier.
“It’s about racking up the points and that can be tough when the opponent is fighting relegation.”
Strasbourg lost 4-3 at Bordeaux where Hwang Ui-Jo hit a hat-trick to lift the home team out of the bottom three.
Bordeaux, who had not scored in three league and cup games this year while conceding 10, hit three in the first 38 minutes but were made to sweat for their victory as their defence then leaked three goals.
“Hwang had a perfect game, he bailed us out on several occasions. He’s had some difficulties in the last few games, so I’m very happy that he’s back,” said Bordeaux’s under-threat coach Vladimir Petkovic.
“I am sorry that we let in three goals,” said Petkovic. “We had a very good first half but then the fear of winning the game took over.”
Rennes took an 18th-minute lead at another struggler Clermont with a goal by Baptiste Santamaria, but missed several other chances and paid in the second half.
Former Rennes player Lucas Da Cunha levelled in the 59th minute and Jordan Tell struck in the 70th minute.
Montpellier beat Monaco 3-2 to climb sixth.
Elye Wahi gave the home team a 13th-minute lead and Stephy Mavididi scored twice, the winner coming in stoppage time.
Wissam Ben Yedder and Vanderson scored for Monaco, who drop to seventh.