Liam Blanchfield emerged as Kilkenny's super substitute at Parnell Park with an injury-time match winning goal to secure a dramatic Leinster SHC Round 1 win.
Pat Gilroy's Dublin led for long spells on their home turf and put themselves in a great position to score a famous win over the Allianz League champions.
They led by five points with five minutes of normal time remaining but were ultimately reeled in by a determined Cats outfit that outscored them by 1-05 to 0-01 in the run-in.
TJ Reid, who scored 12 points overall, Eoin Murphy and Colin Fennelly were on the mark in that late blitzkrieg though it was Blanchfield's fine 71st minute goal that tipped the balance.
The Bennettsbridge man took off on a rampaging run down the left and shortened the hurl for a clever batted finish that broke Dublin hearts.
It was tough on new-look Dublin who lost the inspirational Conal Keaney to a serious looking shoulder injury in the 60th minute.
He'd starred up until then with four points in an attack that was superbly led by former All-Star defender Liam Rushe.
But it's Kilkenny that progress with the crucial win and they will return to action against Offaly at Nowlan Park on May 20.
Dubs chief Gilroy gambled in various departments with his lineout and looked like he might be rewarded with a precious two points.
Starting Rushe at full-forward was the big surprise. The St Pat's man had a brief spell at centre-forward in the past but was viewed as Dublin's likely centre-back under Gilroy.
He also didn't feature much throughout spring due to a fresh rib injury that following groin trouble.
But he caused Kilkenny's full-back line, and Padraig Walsh in particular, huge trouble from the very beginning.
Keaney and Paul Ryan formed a two-man full-forward line for Dublin who dropped wing-forward Jake Malone to midfield and deployed Sean Moran as their sweeper.
That was another big call as Moran, like Malone, spent spring playing with All-Ireland club champions Cuala and only recently rejoined the setup.
The other big move was to shift Eoghan O'Donnell, one of the best full-backs in the game, out to centre-back to mark Reid. Walter Walsh moved out to centre-forward in the second-half and O'Donnell picked him up, holding the big man to a single point.
Dublin were excellent at the back and restricted Kilkenny to just three points from open play in the first-half.
Dublin did have the wind advantage but Kilkenny's inability to score from play was more down to Dublin's greater numbers in defence and their huge work rate around the field.
Up front, Rushe signaled his appetite for destruction with a barnstorming third minute run and lay-off to Ryan who blasted to the net.
It continued in that fashion with Rushe setting up three more points before engineering Dublin's second goal in the 35th minute which Fergal Whitely scored.
Rushe fed Ryan on that occasion and when Ryan's shot was blocked, Whitely raced in to whip the rebound home.
Ryan evaded Joey Holden for a neat point to close out the first-half scoring to leave Dublin sitting pretty at half-time, 2-7 to 0-9.
Kilkenny had the wind after the break but Dublin, crucially, remained in charge on the scoreboard throughout a fascinating second-half.
All eyes were on Cody to see what changes he would make and big guns Fennelly, Conor Fogarty and Paul Murphy were all introduced.
Fennelly hit two points but Dublin's subs were just as influential and Paul Winters and Tomas Connolly contributed 0-03 between them in the second-half.
Keaney's withdrawal with 10 minutes to go was a huge blow to Dublin. He'd been having a great game and hit his fourth point just minutes before going off with a shoulder problem.
Dublin still led by a point entering injury-time but Kilkenny were raiding forward now and Blanchfield effectively sealed it with his excellent solo goal.
Reid rounded off the scoring with a 75th minute point from a free.
Kilkenny: Eoin Murphy (0-04, 0-03f); Joey Holden, Padraig Walsh, Paddy Deegan; Conor Delaney, Cillian Buckley, Enda Morrissey; Richie Leahy, James Maher (0-02); Martin Keoghan, TJ Reid (0-12, 0-9f, 0-02 65), John Donnelly (0-01); Bill Sheehan, Walter Walsh (0-02), Ger Aylward.
Subs: Colin Fennelly (0-03) for Sheehan 33, Conor Fogarty for Keoghan h/t, Paul Murphy for Morrissey (46), Liam Blanchfield (1-00) for Leahy (55), Luke Scanlon for Aylward (59).
Dublin: Alan Nolan; Paddy Smyth, Cian O'Callaghan, Bill O'Carroll; Sean Moran; Chris Crummey (0-01), Eoghan O'Donnell, Shane Barrett; Jake Malone (1-00), Rian McBride; Danny Sutcliffe, Conal Keaney (0-04), Fergal Whitely (1-00); Liam Rushe, Paul Ryan (1-06, 0-05f).
Subs: Fiontan MacGib for Sutcliffe (38-39), Paul Winters (0-03, 0-02f) for Ryan (46), MacGib (0-01) for Whitely (49), Tomas Connolly (0-01) for McBride (53), Ryan O'Dwyer for Keaney (60), Shane Durkin for Malone (66).
Referee: Diarmuid Kirwan (Cork).