Chloe Rollie's last-minute converted try kept Scotland's Rugby World Cup 2021 hopes alive and ended Ireland's dreams of reaching next year's rescheduled tournament.
Replacement fly-half Sarah Law kicked the conversion sending Scotland into the final qualifying tournament.
The result means Italy, who defeated Spain earlier on Saturday, advance automatically to the World Cup.
Ireland will not feature for the first time since 1991.
Scotland had been staring down the barrel of missing out on a third straight World Cup having surrendered a 13-5 lead as the Irish came racing back to hold a five-point advantage in the final minute.
It is a bitterly disappointing result for Ireland, semi-finalists in 2014, who went into the game with one eye on a bonus-point win that would have seen them qualify automatically instead of Italy.
However as they chased Scotland's lead thoughts of four tries were put to one side as they scrambled to remain in contention. It looked as though they had done enough but the Scots, playing with a numerical advantage following Eve Higgins' 77th minute sin-bin, conjured up the decisive try.
They will now join Samoa, the runners-up of the Asian qualifying tournament and the winners of Kenya and Colombia's play-off in the final qualifying tournament, with the winners claiming the 12th and final spot in next year's competition in New Zealand.
Gutsy Scotland see persistence rewarded
All four sides in the European qualifying tournament entered into the final day on five points after two games giving them all a hope of claiming a top-two finish.
However Italy's 34-10 triumph in the day's first match extinguished Spain's hopes of advancing and also ensured Scotland could not qualify automatically even with a bonus-point win of their own, due to Italy's head-to-head advantage.
Ireland, who defeated Italy last weekend, knew securing all five points would send them through in first, so attacked Scotland's try-line early on.
After early attacks were thwarted by handling errors and solid Scottish defending, prop Linda Djougang produced a spectacular burst, driving past four defenders for the game's opening try.
Despite Irish hopes that this opening would prompt a significance surge in momentum, it only served to jolt Scotland into action and when Edel McMahon was shown yellow for making contact with Rachel McLachlan's head, Hannah Nelson knocked over a penalty to put her side on the board.
By the time Ireland were back up to their full compliment Scotland were knocking on the door and eventually found a way in, with Nelson's brilliantly judged kick gathered by Rhona Lloyd to send the Scots into the break with a three-point lead.
Rollie leads Scots to epic win
Having fallen to a shocking opening-round defeat by Spain, Ireland seemingly returned to form in a bonus-point triumph over Italy that reignited their hopes of qualification.
The 2017 World Cup hosts found themselves in deep trouble when Lana Skeldon barged over eight minutes after the break to extend Scotland's lead to eight points, and a bonus-point win was no longer the priority.
Stacey Flood kicked an easy three points as Ireland turned to their most experienced campaigners, Lindsay Peat and Claire Molloy, off the bench. The pair had the desired impact with 40-year-old prop Peat running a brilliant line to finally break Scotland's resistance and put her side back in front.
Another Flood penalty in the 65th minute seemed to send Ireland on their way to victory, but there was a final twist as a scintillating Rollie break up the middle gave Scotland excellent field position with just four minutes left.
Even when centre Higgins was sent to the sin-bin for a tip tackle on Lisa Thomson Ireland looked as though they might hold on with Molloy exacting a huge turnover in her own 22.
However Scotland stayed patient and created numbers on the right, eventually finding Rollie to scamper in and set-up Law for the winning kick.
Ireland: Considine; Murphy Crowe, Higgins, Naoupu Parsons; Flood, Dane; Feely, Moloney, Djougang; Fryday, Monaghan; Wall, McMahon, Griffin (capt).
Replacements: Jones, Peat, Lyons, Hogan, Molloy, Lane, Mulhall, Delany.
Scotland: Rollie; Lloyd, Smith, Thomson, Gaffney; Nelson, Maxwell; Bartlett, Skeldon, Belisle, Wassell, McMillan, Malcolm, McLachlan, Konkel.
Replacements: Wright, Cockburn, Dougan, Bonar, Gallagher, McDonald, Law, Evans.