Chris Maguire and Lynden Gooch both found the net in the dying embers of the game as the Black Cats claimed their first win in three.
But who caught the eye at Priestfield, and who still has work to do?
Scroll down and click through the pages as Phil Smith dishes out his merit marks from a dramatic afternoon in Kent:
1. Lee Burge
Had little to do throughout the contest but produced in the big moment. It was a poor penalty from Graham, but Burge’s save would prove to be crucial in turning the game Sunderland’s way. 7 Photo: Frank Reid
2. Conor McLaughlin
Didn’t have too many opportunities to get forward but got through his defensive work well. Looks a better fit on the right of the back three, rather than as a wing-back, in the current formation. 6 Photo: Frank Reid
3. Tom Flanagan
By and large played well, but was fortunate that his slack pass and foul for the Gillingham penalty did not cost his team. Brought the ball out from the back well as the game developed. 5 Photo: Frank Reid
4. Bailey Wright
A crucial presence at the heart of defence, winning countless headers and duels. Gillingham bombarded the box from set plays but did not turn too many of them into real goalscoring opportunities. 7 Photo: Frank Reid