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.
|Sad if it´s Filipe Luis´ last game for Atletico - Oblak|
|White Sox manager Rick Renteria hospitalised before game|
|Carragher: Van Dijk can become Liverpool legend|
|No timetable for Sale return from shoulder injury|
|This is a partnership - Rodgers on contract negotiations with Packers|
|Eagles QB Wentz unsure he´ll be cleared to play opener|
|Balotelli staying at Nice|
|It wasn´t a penalty, says Hodgson as Palace boss fumes at refereeing decisions|
|Salah can play much better - Klopp demands more from Liverpool star|
|Gasly to Red Bull: Vettel, Verstappen and the drivers who took their Toro Rosso chance|
|Klopp in the dark on Karius future amid links to Besiktas|
|Simeone pleased with draw after rigours of Super Cup|
|Captain Reus saves Dortmund in DFB-Pokal|
|I couldn´t care less - Klopp rejects title challenge talk|
|Ailing Bairstow keen to aid England´s unlikely victory bid at Trent Bridge|
|Redskins secure Peterson signing|
|Manchester City goalkeeper Bravo suffers ruptured Achilles|
|Crystal Palace 0 Liverpool 2: Milner and Mane secure victory at Selhurst Park|
|Whyte takes aim at ´coward´ Fury ahead of Wilder showdown|
|Jets delighted with Darnold, open to trading Bridgewater|
|Gasly to replace Ricciardo at Red Bull|
|Valencia 1 Atletico Madrid 1: Rodrigo strikes to deny Simeone´s side|
|Injured Halep withdraws from Connecticut Open|
|Cipriani fined £2,000 by Gloucester|
|Mourinho will be sacked before Christmas, says Sharpe|
|England face record chase after Kohli smashes India to huge lead|
|Ozil captaining Arsenal a miracle - Hoeness|
|Japan players apologise for ´thoughtless, careless´ actions at Asian Games|
|Henry wants Bordeaux job, Wenger confirms|
|Pogba too inconsistent and not a leader, claims Scholes|
|PCB chairman Sethi resigns in letter to Pakistan prime minister Imran Khan|
|US Open comes too soon for Tsonga|
|Unpredictable results making 2018 F1 season a classic - Wolff|
|Mendy restricts phone use on Guardiola advice|
|Modric brands Inter approach claim ´the greatest nonsense in history´|
|Runners and Ryders: Olesen leapfrogs Poulter into last Team Europe berth|
|Kenedy escapes further action over Camarasa kick|
|England´s Bairstow suffers ´small fracture´ to finger|
|Gonalons joins Sevilla on loan from Roma|
|Modric, Ronaldo and Salah final UEFA Player of the Year nominees|
|Tottenham to play opening Champions League home match at Wembley|
|Karius´ Champions League blunders did not lead to Alisson signing - Klopp|
|Leeds considered €20m Conte offer before turning to Bielsa|
|Modric, Rakitic lead new era for World Cup finalists Croatia|
|Storm´s Chambers banned for three weeks, Smith injury not serious|
|Porte to race Vuelta after recovering from Tour crash|
|The Career Golden Masters: A run-down of Djokovic´s magnificent record|
|Japan send home four basketball players from Asian Games amid prostitution scandal|
|Rugby tackle bags helping Liverpool´s Alisson with Premier League life|
|Federer raring to go at US Open after Djokovic defeat|
|Chelsea boss Sarri plans to give up smoking|
|Alonso´s Toyota team stripped of Silverstone victory|
|Ceballos: No issue with former Real Madrid boss Zidane|
|MLS Review: Martinez equals single-season goalscoring record|
|Astros avoid sweep with win over Athletics|
|Seppi advances, Paire exits Winston-Salem|
|Bale feeling good as Madrid eye sweep of trophies|
|You can´t leave a house three-quarters built – Neville urges United to back Mourinho|
|Dodgers slugger Machado leaves game after being struck by pitch|
|Harden says Carmelo will ´be a good fit´ for Rockets|
|Morata: I never considered Chelsea exit|
|Gavrilova kicks off title defence in New Haven|
|Lopetegui pleased with Bale and Real Madrid after LaLiga opener|
|It´s a very special moment – Djokovic revels in Golden Masters achievement|
|Sorrentino thanks Ronaldo for support after injury|
|Twins place Santana on DL with finger injury|
|Yankees´ Gregorius suffers ´pretty significant´ heel bruise|
|Snedeker ends PGA Tour drought with Wyndham Championship win|
|Spalletti unconcerned despite Inter´s underwhelming start|
|Djokovic makes history with Masters clean sweep in Cincinnati|