Andrew Tutte and Bobby Grant notched either side of half-time as Rochdale ended 10-man Gillingham's undefeated league record this season with a 2-1 win.
Despite winning their last four, the hosts were behind after 15 minutes when Tutte collected a short corner on the left and his inswinging cross evaded everyone and nestled in the far corner.
The hosts responded when Danny Jackman's free-kick was deflected behind, Deon Burton volleyed over from close range and Matt Fish fired over after a quick counter-attack.
However, Jackman lunged in on Tutte to receive a straight red card just after the half hour, and if Ryan Edwards had kept his cool when the resulting free-kick fell to him inside the box, the game could have been up.
The match became stretched after the break and the visitors took advantage, Tutte releasing Grant on the right and, after seeing his effort saved by Stuart Nelson, the winger drilled in the rebound.
Chris Whelpdale was hauled down by George Donnelly in the area and substitute Danny Kedwell converted the penalty to give the home side hope with 15 minutes to go, but Rochdale held on.