Substitute Malaury Martin smashed in a 90th-minute free-kick as Middlesbrough ended Bristol City's six-game unbeaten run with a 1-0 win.
The midfielder had only been on the pitch for 13 minutes, but he crashed the ball past Robins goalkeeper David James from 25 yards to ensure Boro closed the gap on the npower Championship's leaders.
The hosts, who had been enjoying a resurgence since manager Derek McInnes arrived at the helm, will feel they deserved at least a point.
The visitors' goalkeeper Jason Steele made a point-blank save from Nicky Maynard in the first half then cleared substitute Brett Pitman's goal-bound effort off the line in the second period.
The Robins also felt they should have had a penalty midway through the second half after the ball clearly struck Julio Arca's hand, but referee James Linington waved away the protests.
Both sides appeared content to share the spoils before Martin popped up at the death to secure an unlikely victory for Tony Mowbray's side.
The hosts were enjoying plenty of joy down the right wing early on and they fashioned two of the half's best chances.
In the 12th minute, the lively Albert Adomah pulled the ball back for Neil Kilkenny who fed Maynard inside the box, but his placed shot was comfortable for Steele.
Moments later Steele had to make a double stop. He should have done better at first as he pushed Martyn Woolford's volley away rather than catching it, but he redeemed himself by blocking the rebound from Maynard.
The visitors' strike duo Marvin Emnes and Scott McDonald were starved of first-half chances and it was right-back Justin Hoyte who went closest early in the second period.
He ventured forward from his position as the Robins cleared a corner and the former Arsenal defender hit a swerving drive which narrowly went over the crossbar.
Mowbray's side were gathering momentum and Emnes finally had a shot on target, cutting inside before driving straight into James' arms.
At the other end, Joe Bennett was caught in possession and Adomah nearly capitalised but his venomous shot was beaten away by Steele.
The Ashton Gate faithful felt their side were denied a clear penalty in the 71st minute when Kilkenny's cross struck Arca's raised arm.
McInnes threw Pitman on in a bid to break the deadlock and it very nearly worked. Adomah smashed the ball across the six-yard box and it appeared to be creeping in after striking Pitman on both legs, but Steele scrambled back to claw the ball away.
And it was another substitute who provided the telling contribution at the other end.
Emnes jinked past James Wilson who upended him and Martin blasted the free-kick across James and into the top corner to send the visiting fans behind that goal into delirium.
Bristol City 0-1 Middlesbrough: Match Report - view commentary, squad, and statictics of the game as it happened.