Paul Parry scored the late goal that ensured another season of Coca-Cola Championship football for Cardiff - but it pitched Gillingham into a final-day scramble for safety.
When promising 18-year-old Matthew Jarvis put Stan Ternent's side ahead with 19 minutes left it looked like the hosts were guaranteed to stay up given Crewe's capitulation at Ipswich.
But Parry turned the situation around and Gillingham must win away to relegated Nottingham Forest next weekend to be sure of avoiding relegation.
In a largely disappointing game, Cardiff striker Cameron Jerome was first to try his luck from 25 yards but his fifth-minute volley was held by goalkeeper Jason Brown.
At the other end four minutes later, Neil Alexander did even better to tip a Darius Henderson header over the crossbar and as Gillingham began to settle, Mamady Sidibe, back in the side after a hamstring injury, fired wide.
Sidibe did good work in his own penalty area after 25 minutes as he blocked a Richard Langley shot and Jerome continued to look the most likely Cardiff player to break the deadlock, producing another save from Brown nine minutes later.
Gills duo Michael Flynn and Nicky Southall blasted long-range efforts off target as a disappointing opening period drew to a close.
It was equally lifeless after the break until James Collins blocked a Henderson volley in the 59th minute and the hosts attempted to turn things in their favour by sending on Jarvis and Darren Byfield for Flynn, while Parry
replaced Cardiff's Jobi McAnuff.
Less than 90 seconds after his introduction Byfield missed the best chance so far, heading wide when well positioned.
Sidibe also squandered a fine opportunity, heading the ball into Alexander's hands from a Southall corner, but the momentum was with Gillingham now and they took the lead with 19 minutes left as Jarvis drove home an angled left-foot shot.
Parry and Collins both volleyed over the crossbar as Cardiff sought an equaliser. But the Wales international winger succeeded in restoring parity with six minutes left when he headed home from a Neil Ardley cross.
Teams
Gillingham Brown, Nosworthy, Ashby, Cox, McEveley (Hope 90),
Southall, Smith, Douglas, Flynn (Jarvis 61),
Henderson (Byfield 67), Sidibe.
Subs Not Used: Banks, Crofts.
Booked: McEveley.
Goals: Jarvis 72.
Cardiff Alexander, Williams (Bullock 77), Gabbidon, Collins,
Barker, Ardley, Langley, Boland, McAnuff (Parry 66), Thorne,
Jerome (Lee 71).
Subs Not Used: Margetson, Vidmar.
Goals: Parry 85.
Att: 10,810
Ref: A Kaye (W Yorkshire).