King coolly levelled the scores after Bradford captain Robert Molenaar had sent Mali international Mamady Sidibe crashing and wrapped up Gillingham's first win in eight matches with a stunning 25-yard strike.
With experienced players available again after injury Bradford looked more solid at the back and there were few clear-cut chances early on.
Bradford's defence had leaked 20 goals in the last eight games but Gillingham rarely tested keeper Aidan Davison in the opening period.
Midfielder Paul Shaw had a left-foot strike pushed away and it was City who deserved to get their noses in front.
On-loan striker Delroy Facey wasted a great chance when he was clean through but his partner Gray bagged his sixth of the season four minutes before the break.
Midfielder Lewis Emanuel created the goal with his break down the left wing and when his cross reached Gray in the six-yard box he forced the ball past stranded keeper Jason Brown.
But that was as good as it got for City as Gillingham staged a second-half revival.
Facey missed another gilt-edged chance when he was one-on-one with Brown and the turning point came in the 58th minute.
Gillingham full back Nayron Nosworthy headed the ball back into the City box and although Sidibe looked offside he was clattered from behind by Molenaar.
Referee Michael Ryan pointed to the spot and King kept his head to sidefoot home the penalty with Davison diving the wrong way.
Experienced defender David Wetherall was thrown into the action after a three-month injury lay-off but he could do nothing when King picked up a loose ball after 74 minutes and fired home a curling right-foot drive from 25 yards.
There was no way back for City and substitute striker Rod Wallace sealed victory with a neat right-foot finish seven minutes into stoppage time.