Messi converted a Nuno Mendes cross in the 26th minute before Gianluigi Donnarumma produced several key saves and Dante was denied by the woodwork as PSG's goal lived a charmed life on the Cote d'Azur.
Ramos then ended any doubt about the outcome when he headed in a Messi corner with 14 minutes remaining, as PSG bounced back from suffering consecutive home defeats.
A win for nearest challengers Lens on Friday had cut PSG's lead at the top of the table to just three points before this game, and before the top two meet in Paris next weekend.
It was a first defeat in 15 matches in all competitions for Nice since former PSG midfielder Didier Digard replaced Lucien Favre as coach in January. They remain eighth in the table.
Galtier was booed by sections of the home support in Nice, the club he left last year to join PSG, but he saw Messi silence the crowd with the opening goal.
Before that, Danilo Pereira had already hit the woodwork for the visitors, who also saw injury-prone midfielder Renato Sanches come off hurt early on.
Donnarumma saved well from Nicolas Pepe and Terem Moffi before half-time, and Dante then sent an effort off the underside of the bar six minutes into the second half, with the ball bouncing down onto the line and then hitting the post.
It was an incredible let-off for the league leaders, who were grateful to Donnarumma again as he made further stops from Pepe and Youssouf Ndayishimiye.
Ramos made it 2-0 but there was still time for Danilo to head against his own crossbar late on.
Marseille can rejoin Lens and close back to within six points of PSG with a win at Lorient on Sunday.