An early goal from Bradley Dack extended Gillingham's unbeaten run to four matches on Saturday.
Dack headed the Gills in front on 14 minutes and they ended up playing against nine men after Rochdale had two players sent off in the space of six second-half minutes.
But it was a nervy finish at Priestfield as the men from the north-west threw caution to the wind in pursuit of an equaliser.
For the Gills, Brennan Dickenson started his first league game since January 3 in Justin Edinburgh's only personnel change from the 2-2 draw at Preston in midweek. The man to make way was Amari'i Bell, who had to settle for a place on the bench.
There were three changes for Rochdale, who'd lost 4-2 at home to Swindon on Tuesday. Manager Keith Hill dropped Rhys Bennett, Michael Rose and Joe Bunney in favour of Matty Lund, Calvin Andrew and Reuben Noble-Lazarus.
Lund was making his first appearance since Boxing Day following a shoulder injury.
There was real instenity about Gillingham's early play and they quickly forced a mistake. Dack pounced on Tom Kennedy's heavy touch and won a corner, although Doug Loft's inswinging delivery from the right failed to beat the first defender.
The first 10 minutes were played out largely in the Dale half, with Loft smashing an optimistic volley high and wide.
Some nice interplay between Dack, John Marquis and Cody McDonald had the visitors on the back foot and following good work by Marquis on the edge of the box, McDonald found himself with a clear sight of goal. His first touch was heavy but Rochdale didn't clear the danger and Aaron Morris' powerful drive from 25 yards was deflected behind.
From the resulting corner came Gillingham's goal. The goal was simplicity itself, Loft curling a corner to the near post and Dack powering a header beyond Dale keeper Jamie Jones.
It took Rochdale a while to get into the game but eventually they did, with Reuben Noble-Lazarus shooting straight at Glenn Morris.
Jamie Allen then found Noble-Lazarus in space on the left-hand side of the Gills box. His shot was heading for the far corner until it struck his team-mate Ian Henderson, allowing the hosts to clear their lines.
At the other end, Jermaine McGlashan did well to dig out a right-wing cross but despite a good leap from McDonald in the middle, he couldn't keep his header down.
Rochdale came within inches of equalising when Henderson's cross from the left floated over Glenn Morris' head and struck the inside of the far post. The ball dropped for Allen near the penalty spot but his shot was well blocked by a Gills defender.
Marquis sliced a corner over his own crossbar just before half-time and Lund sent a header just past the near post from the corner which followed.
When play resumed, Allen headed wide from a Henderson cross and Loft then went in strongly on Dale winger Andy Cannon, whose first-half histrionics had made him the pantomime villain of Priestfield. Rochdale's players surrounded referee Andy D'Urso but the former Premier League referee took his time and showed Loft a yellow card rather than red.
That incident seemed to spark Gillingham back into life.
Marquis picked out the overlapping McGlashan and his deep cross from the right was headed wide by McDonald, arriving late at the back post.
Dickenson then crossed from the opposite flank after being cleverly played in by Loft. His ball in was headed goalwards by Marquis, whose effort was blocked.
The game had been bubbling along nicely but then it burst into life.
Jones charged out of his box and brought down McDonald, with players from both sides piling into the melee which followed. It looked like Jones aimed a punch at one of the Gills players in the scuffle and after consulting with his assistant, Mr D'Urso sent Jones off.
Rochdale rallied, Cannon going close on the counter-attack and Rose forcing Glenn Morris to tip his 35-yard free-kick over the bar.
But a bad afternoon got even worse for the visitors when Lund threw himself into a wild challenge on Dack near the touchline. Out came the red card for a second time and Lund followed his goalkeeper down the tunnel.
John Egan strode out of defence to sting the palms of Rochdale's substitute keeper Josh Lillis but Rochdale refused to give in. Joe Rafferty had his head in his hands after shooting wastefully wide from a good position inside the Gillingham box.
Rose drilled a shot over in the closing stages but the Gills saw out six minutes of stoppage-time to claim the points.
Gillingham: G Morris, Egan, Legge, Ehmer, McGlashan (Bell 89mins), Dack, A Morris, Loft (Pritchard 80mins), Dickenson, Marquis, McDonald (Norris 73mins). Subs not used: Nelson, Hessenthaler, Muldoon, Hoyte.
Rochdale: Jones, Rafferty, Eastham, Vincenti (Lillis 64mins), Lund, Andrew (Logan 61mins), Noble-Lazarus (Rose 52mins), Allen, Cannon, Kennedy, Henderson. Subs not used: Bennett, Lancashire, Camps, Bunney.
Attendance: 5,430 (163 away)