Sunderland moved up to fourth in Division One thanks to goals from Sean Thornton and Darren Byfield.
Thornton gave the FA Cup semi-finalists the lead in the 11th minute with a stunning free-kick.
Patrick Agyemang grabbed a fortuitous leveller in the 28th minute - which he knew very little about.
But the home team's lead was restored in the 53rd minute thanks to Byfield, who netted from the edge of the box to send Mick McCarthy's team above Wigan.
The result extended the Black Cats' unbeaten run at home to 17 league games and ensured Gillingham's first trip to the Stadium of Light ended fruitless.
The opener from Thornton was the culmination of a sustained spell of Sunderland pressure which saw Paul Thirlwell fire over from distance and John Oster test keeper Steve Banks early on.
And then Thornton rewarded the home side's efforts when he found the top corner of Banks' goal following Leon Johnson's foul on Byfield.
Kevin Kyle, with a left-footed strike, and Oster failed to find the target as Sunderland sought to double their advantage.
But Gillingham came into the game more as the half progressed with the leveller coming when Agyemang diverted a cross past keeper Mart Poom off his thigh.
Stephen Wright was forced off through injury for Sunderland while Jeff Whitley and Kyle stung Banks' palms and Byfield shot wide before the break.
Sunderland regained the lead in the 53rd minute as Byfield netted his third goal in as many games.
He collected the ball 40 yards from goal and ended a jinking run with a low shot to Banks' right.
Sunderland: Poom, McCartney, Babb, Breen, Wright, Oster, Whitley, Thirlwell, Thornton, Byfield, Kyle.
Subs: Piper, Tommy Smith, Cooper, Williams, Myhre.
Gillingham: Banks, Rose, Ashby, Leon Johnson, Southall, Pouton, Smith, James, Spiller, Sidibe, Agyemang.
Subs: Hessenthaler, Crofts, Jarvis, Awuah, Beckwith.
Referee: M Cowburn (Lancashire)