Kevin O'Brien scored Ireland's first Test century to bolster hopes of at least avoiding defeat in their debut in the five-day game against Pakistan.
Ireland resumed day four on 64-0 in their second innings having been forced to follow-on by the visitors, who reduced the hosts to 157-6 to seemingly put them in position for an emphatic victory.
Mohammad Amir, having been troubled by a knee injury on day three, looked back to fitness and form on Monday and did much of the damage with figures of 3-57.
But Amir and the rest of the Pakistan attack were frustrated by the brilliance of O'Brien, who forged a pivotal partnership of 114 with Stuart Thompson (53) and an unbroken one of 48 with Tyrone Kane (8), staying unbeaten on 118 to guide Ireland to 319-7 at the close on an historic day at Malahide.
Ireland therefore lead by 139 going into the final day, with a draw and even a victory still within their grasp after being applauded off the field by Pakistan at stumps following O'Brien's magnificent effort.
Opener Ed Joyce (43) was run out by Faheem Ashraf before Andy Balbirnie went for a duck five balls later as Ireland made a dreadful start to the day.
The prospect of defeat loomed ever larger after Amir dismissed any doubts over his ability to produce pace by sending Niall O'Brien's (18) off and middle stumps careering out of the ground, before then claiming the scalp of captain William Porterfield (32).
O'Brien's arrival at the crease prompted the first signs of Ireland resistance but wickets continued to tumble around him until Thompson joined him in the middle.
Their defiance ensured Ireland would not only avoid an innings defeat but also give their own attack something to bowl at in Pakistan's second innings.
And, though a ripper from Shadab Khan removed Thompson, O'Brien proved immovable, his belligerent strokes keeping the scoreboard ticking before he wrote his name in the history books by sneaking two through point to bring up his hundred.
O'Brien and Kane withstood pressure from Amir, Rahat Ali and Mohammad Abbas late in the day, and Ireland go into the last three sessions with the unexpected dilemma of deciding how long to bat before attempting to bowl Pakistan out to seal a seismic shock win.
|Tiger charges into four-shot lead|
|Players have given their lives to Burnley - Dyche|
|QPR 0 Norwich City 1: Pukki hits winner as hot streak continues|
|Nuno proud of Wolves character in Man United draw|
|Playing for England my dream, says in-form Maddison|
|Brighton and Hove Albion 1 Tottenham 2: Kane on target as Spurs issue firm response|
|Schalke 0 Bayern Munich 2: James and Lewandowski deliver another win|
|Getafe 0 Atletico Madrid 2: Lemar inspires routine win|
|Championship Review: Monk ruins Leeds´ unbeaten streak, McGinn screamer fails to save Villa|
|Bale benched for Real Madrid-Espanyol|
|Biggar fails to rescue Saints at Bath, Bristol and Wasps win|
|Zaha affected by back injury – Hodgson|
|Mourinho slams Manchester United attitude after Wolves stalemate|
|Herbert holds Portugal Masters advantage|
|Warnock blasts ´elementary´ Cardiff mistakes|
|Shaqiri substitution not easy for Klopp|
|Guardiola hopes for even more to come from Aguero|
|Fellaini accepts United closing gap to Premier League summit will be difficult|
|Klizan to face Thiem in St. Petersburg final, Bachinger shocks Nishikori|
|Klopp: Van Dijk injury not serious|
|Mourinho annoyed by Man Utd´s blunt attack in Wolves draw|
|Valverde not ready to consider Barca contract extension|
|Gattuso wary of wounded Atalanta as Higuain receives further advice|
|Burnley 4 Bournemouth 0: Rampant Clarets claim first Premier League win of the season|
|Crystal Palace 0 Newcastle United 0: Sakho misses sitter as Magpies remain winless|
|Cardiff City 0 Manchester City 5: Aguero celebrates new deal with goal in 300th game|
|Leicester City 3 Huddersfield Town 1: Comeback win eases pressure on Puel|
|Liverpool 3 Southampton 0: Salah ends goalless run as Reds make best Premier League start|
|Manchester United 1 Wolves 1: Moutinho stunner sees Red Devils falter at home again|
|Rashid, Hasan and Asghar fined by ICC|
|Barnsley game postponed after medical emergency|
|Johnny Manziel sacked five times in ugly CFL loss|
|Fosu-Mensah says sorry for tackle on Deeney|
|Kluivert to get Roma chance as Di Francesco demands focus|
|Robinson optimistic injured Cronk will be fit for Grand Final|
|WATCH: Ferguson given immense ovation on Old Trafford return|
|Three in a row for Lorenzo at Aragon|
|Warner makes 155 on Australian grade cricket return|
|Pain-free Kyrie Irving ready to lead Celtics to NBA title|
|Firmino returns as Shaqiri gets first league start|
|Fulham 1 Watford 1: Mitrovic shines late to spoil Gray´s day|
|Ronaldo vows to lose weight and assist training after Real Valladolid purchase|
|Patriots WR Josh Gordon listed as questionable to face Lions|
|500th goal was crucial to my new book - Ibrahimovic|
|Roosters survive Cronk injury to hold off Souths and reach Grand Final|
|Murray announces intention to end season early|
|I want to play right-back for England - Walker|
|I would beat Bolt for speed on the pitch, claims Traore|
|Ferguson returns to Old Trafford for Manchester United v Wolves|
|Walker ´hurt´ by Pochettino claims over Tottenham exit|
|Douglas Costa has paid his fine for Sassuolo spitting incident – Allegri|
|Djokovic: Sock gave me karma back for hitting Federer|
|Anthony Joshua v Alexander Povetkin: Tale of the tape|
|Wang thrashes Putintseva to win Guangzhou title|
|There is no problem with Cavani - Tuchel silences rumours of PSG rift|
|Wilder & Fury sign contracts for December 1 bout|
|Neymar is the Kim Kardashian of football, claims Barton|
|We did not want to sell him - Perez insists Madrid got ´highest value´ for Ronaldo|
|Osaka continues run, Pliskova awaits in Tokyo final|
|Cardinals keep pace in wildcard race with win over Giants|
|Djokovic hits Federer, pair lose in doubles at Laver Cup|
|Nowitzki likely to come off bench for Mavericks in 21st season|
|Red Wings´ Green battling ´virus that attacked his liver´|
|They said I couldn´t score goals – Ibrahimovic hits back at early critics|
|Slater charged, set to miss Grand Final|
|Rose not changing approach alongside Woods|
|Woods ready to ´hang in there´ at East Lake|
|Shaqiri´s time will come at Liverpool – Klopp|
|Richarlison: I used to copy some of Neymar´s haircuts|
|Brady says Gordon is ´really eager to get in there´ despite limited practice|