Gillingham 1 Cardiff 2
By Andy Clarke
Last Updated: 01/01/70 1:00am
Lee Bullock scored a late winner for Cardiff to keep Lennie Lawrence's men in with a slim chance of reaching the play-offs.
Robert Earnshaw, who had earlier missed from the penalty spot, gave the Bluebirds the lead before Chris Hope levelled for Gillingham, who remain just two points outside the relegation zone.
Bullock, on loan at Ninian Park from York, headed in just four minutes from time but Gillingham missed a golden opportunity to claim a point in the closing seconds.
Referee Mike Thorpe awarded a penalty for Chris Barker's challenge on Gary Wales, but Gills midfielder Alan Pouton placed his kick wide of goal.
Thorpe had awarded Cardiff a penalty inside 20 minutes, when Leon Johnson brought down Alan Lee, but Steve Banks produced a fine save to deny Earnshaw.
The Wales international was not to be denied, however, and he put the visitors ahead on 36 minutes, nodding into an empty net after Paul Parry had taken the ball around Banks.
Gillingham went close through Wales and Mamady Sidibe early in the second half, before they levelled when Hope rose highest to head in Nicky Southall's corner.
Richard Langley forced a fine save from Banks as Cardiff responded well, before late substitute Bullock headed in the winner for the Welshmen.