Carnegie got on the wrong side of Irish referee Jonny Erskine in the first half, then, when it looked like they’d done enough to turn things around, succumbed to the sucker punch off the last play of the game.
Dragons were reduced to 14 players just before half-time, when Carnegie appeared to get the upper hand.
The visitors took an unlikely lead just before the break when Taylor Prell made an exciting break and the back-pedalling Dragons eventually conceded a penalty.
Second-row Henri Williams was dispatched to the sin-bin while Warren Seals kicked the penalty conversion to make it 8-5 at the break.
Carnegie came out determined to make their numerical advantage pay, and they crossed for their second try inside five minutes of the second-half re-start.
Yorkshire kicked a penalty to the corner, kept the ball tight and Chris Walker drove hard to the line for the touchdown with two defenders still on his back.
Seals added the conversion to make it 15-5.
But Dragons hit back with a penalty from Robson, and the home side levelled the game with 20 minutes to go when Nathan Hudd went over from close range.
Arwel Robson tagged on the extras to make it 15 apiece.
Carnegie then lost Charlie Beech to the sin-bin. Yorkshire defended well and a counter-attack from Walker took them upfield, and, from a penalty, Rob O’Donnell powered over the try line. Unfortunately, Seals was unable to convert from wide out, but with 10 minutes left on the clock the visitors must have fancied their chances.
But Robson popped up on the final play of the match and nipped over for the match-levelling try. The fly-half then converted from the touchline to seal victory, 22-20.
Earlier, Dragons had opened the scoring after only two minutes of the game, Joe Goodchild touching down after Max Green’s box kick had been charged down and Darran Harris had put Dragons on the front foot. Robson missed the conversion, and a subsequent penalty attempt.
South African-born back-rower Brandon Staples got Yorkshire Carnegie’s tryscoring off the mark in reply.