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.
|Suns star Booker set to return for season opener|
|Warriors coach Kerr not expecting fast start from NBA champs|
|Fultz to start for 76ers as Brown eyes NBA Finals|
|Maltese champions Valletta want Usain Bolt|
|It would have been normal to kill them! Luis Enrique slams abysmal Spain|
|Seahawks, Trail Blazers owner Paul Allen dies aged 65|
|Red Sox ace Sale released from hospital, still set for game five|
|Beer-throwing fan banned by Patriots|
|Southgate lauds ´tremendous´ attackers after famous Spain win|
|Djokovic closing in on summit as he scales new heights|
|Monaco the natural move for Henry - Martinez|
|Ending England drought a ´beautiful feeling´ – Sterling|
|Halep to face Pavlyuchenkova in Moscow comeback|
|NBA 2018-19: Five non-LeBron James storylines to follow|
|Spain 2 England 3: Kane inspires Three Lions as Sterling ends drought in style|
|Bosnia-Herzegovina 2 Northern Ireland 0: Dzeko double leaves O´Neill´s side on the brink|
|Mannarino stops the rot in Moscow|
|Neymar pleased Brazil will not face Messi in Argentina clash|
|Buccaneers fire defensive coordinator Mike Smith after loss to Falcons|
|´Surprised´ Deschamps accepts he could´ve made more effort with Koscielny|
|Kuwait 0 Australia 4: Socceroos deliver win for new coach Arnold|
|Van Dijk fit for Liverpool return - Koeman|
|NBA 2018-19: Eastern Conference predictions|
|NBA 2018-19: Five rookies to watch|
|Denly replaces injured Dawson in England ODI squad|
|Low confirms under-fire Neuer to start against France|
|NBA 2018-19: Western Conference predictions|
|Bolt offered two-year deal by European club, says agent|
|NBA 2018-19: LeBron the Laker - what it means|
|Griezmann ahead of Mbappe for Ballon d´Or - Modric|
|Billy Vunipola ruled out with fractured arm|
|Get the chequebook out! - Mayweather talks up potential Khabib clash|
|Amla ruled out of Australia tour|
|Class act Hamilton more complete than ever - Wolff|
|NBA 2018-19: It´s a big season for - Ball, Kawhi, Carmelo, Love & Cousins|
|Bellew: I have no fear of Usyk|
|Birthday boy Ozil is the most creative player in Europe|
|CSA reveals De Villiers and Rabada involved in Mzansi Super League|
|FA condemns England supporters involved in trouble in Seville|
|Gascoigne hits back over Scottish Hall of Fame snub|
|NBA 2018-19: LeBron closing in on Jordan, Curry chasing Miller and Allen|
|Ter Stegen should start ahead of Neuer for Germany – Matthaus|
|England´s Sterling impressed by Sancho´s work ethic|
|Vandoorne seals switch to Formula E|
|Halep to end 2018 as world number one|
|Sri Lanka´s Jayasuriya charged by ICC with breaching anti-corruption code|
|Vermaelen out for six weeks with hamstring injury|
|LeBron and Irving did not fall out, says ex-Cavs trainer|
|Ramsey out of Wales´ clash with Republic of Ireland|
|Bolt angry with drugs test|
|Bad luck is not a coincidence – Kimmich concerned by Germany form|
|Mahomes: Chiefs need to win like Brady and the Patriots|
|Schuster warns Real Madrid not to panic-buy striker in January|
|We´re here to win! - Paine not happy celebrating a draw|
|Injured Thauvin out of Germany clash|
|Southgate hits out at early Premier League start|
|Modric to Inter talk is ´fantasy´, says Guardiola|
|Pats hand first loss to Chiefs after wild shoot-out|
|Cowboys, Ravens dominate as Pats beat Chiefs in NFL classic|
|Brady becomes first QB to 200 regular-season wins in NFL|
|Red Sox level series against Astros|
|Mbappe leaves red-faced Dembele on his backside|
|Red Sox ace Sale admitted to hospital with stomach illness|
|From UFC to NFL? McGregor throws pass for Cowboys|
|Ancelotti praises ´dangerous´ Mbappe|
|Uncapped Papalii named in All Blacks squad|
|Kane would star in LaLiga – Ramos|
|Guardiola unsure about Man City´s Champions League chances|
|Dzeko: Premier League return? You never know|
|Gurley dominates to help Rams beat Broncos|