The Scots started well and tries from Nairn Moncrieff, Seb Stephen and Oliver Duncan gave them a 17-7 lead at the interval.
Ireland stormed back in the second period with two converted tries putting them ahead 21-17 with ten minutes remaining.
Scotland looked like they had missed their chance for the win but Jake Shearer powered over in the last minute to give his side a deserved 22-21 win.
Scotland U20
15 Jack Brown (Edinburgh Rugby)
14 Nairn Moncrieff (Edinburgh Rugby)
13 Johnny Ventisei - Co-captain (Glasgow Warriors)
12 Kerr Yule (Glasgow Warriors)
11 Fergus Watson (Glasgow Warriors)
10 Matthew Urwin (Glasgow Warriors)
9 Hector Patterson (Edinburgh Rugby)
1 Ollie McKenna (Glasgow Warriors)
2 Seb Stephen (Edinburgh Academical FC/Glasgow Warriors)
3 Ollie Blyth-Lafferty (Edinburgh Rugby)
4 Dylan Cockburn (Melrose RFC/ Glasgow Warriors)
5 Bart Godsell (Loughborough University)
6 Oliver Duncan (Edinburgh Rugby)
7 Freddy Douglas - Co-captain (Edinburgh Rugby)
8 Reuben Logan (Northampton Saints)
Substitutes
16 Joe Roberts (Glasgow Warriors)
17 Ben White (Melrose RFC/Edinburgh Rugby)
18 Jake Shearer (Glasgow Warriors)
19 Charlie Moss (Montpellier)
20 Mark Fyffe (University of Edinburgh)
21 Noah Cowan (Brunel University/Ealing Trailfinders)
22 Jack Hocking (Unattached)
23 Jed Findlay (Exeter Chiefs)