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.
|Kovac relieved by Bayern´s timely victory|
|Strasbourg 2 Monaco 1: Sy howler and Grandsir red card cost Henry in first match|
|Leicester City defender Chilwell signs new six-year contract|
|PSG´s Tuchel hopes Verratti and Di Maria can face Napoli|
|Liverpool star Salah had no fear during scoring drought|
|Alonso´s 2019 plans not damaged by McLaren´s IndyCar decision|
|Edinburgh outclass troubled Toulon, Wasps and Bath play out thrilling draw|
|Barca concern as Messi substituted with worrying arm injury|
|Howe: South coast derby draw a fair result|
|Our heads were in Manchester – Allegri left fuming at Juventus´ loss of focus|
|Derby County 2 Sheffield United 1: Marriott blunts Blades with 77th-minute winner|
|We have so many problems – Jokanovic alarmed by Fulham defensive woes|
|Huddersfield Town 0 Liverpool 1: Salah snaps winless streak|
|Pellegrini ruing injuries after Yarmolenko hurts ankle|
|Villarreal 1 Atletico Madrid 1: Simeone´s side denied LaLiga top spot|
|Gracia: Not easy to dominate Wolves like that|
|Isner´s Finals hopes hindered by Stockholm defeat|
|Dyche incredulous at refereeing decisions in Man City thrashing|
|Juventus 1 Genoa 1: Champions´ winning run ends despite record Ronaldo goal|
|´Fantastic´ Lamela urged to find consistency by Pochettino|
|You don´t want to lose any players - Young speaks out on Wade NFL speculation|
|Championship Review: Smith gets off to a winning start, Leeds beaten|
|Guardiola hails extraordinary Fernandinho after Burnley drubbing|
|Pochettino lauds Lloris as one of world´s best after West Ham heroics|
|Paris Saint-Germain 5 Amiens 0: Ten wins in a row for PSG as Neymar rests|
|Cristiano Ronaldo nets record 400th league goal|
|Marcelo backing beleaguered Lopetegui despite Madrid slump|
|Garcia dazzles to hit the front at shortened Valderrama Masters|
|Cardiff City 4 Fulham 2: Paterson gets Bluebirds off the mark|
|Newcastle United 0 Brighton and Hove Albion 1: Benitez´s men bottom after dismal defeat|
|West Ham 0 Tottenham 1: In-form Lamela settles London derby|
|Manchester City 5 Burnley 0: De Bruyne returns in comfortable win|
|Wolves 0 Watford 2: Capoue and Pereyra turn form book on its head|
|Bournemouth 0 Southampton 0: Howe´s side stifled by Saints|
|Prove you´re crazy about Inter - Spalletti rallies players ahead of Milan derby|
|Wolfsburg 1 Bayern Munich 3: Lewandowski leads Kovac out of trouble|
|Goerges betters Bencic to clinch Luxembourg title|
|Morgan wants more from ´rusty´ England despite series win|
|Sarri says sorry after touchline bust-up overshadows Chelsea´s late escape|
|Chelsea draw an ´awful´ result for excellent United, says Mourinho|
|The Chelsea assistant that angered Mourinho - Who is Marco Ianni?|
|Steve Kerr supports Colin Kaepernick: ´I think he deserves a chance to play´|
|Lopetegui ´more motivated than ever´ amid Real Madrid sack reports|
|That´s football – Rudiger shrugs off late Ianni-Mourinho fracas|
|AC Milan´s improved mentality could be difference against Inter - Gattuso|
|Emotional Kasatkina comes back from the brink to win Kremlin Cup|
|Forget it, it´s over - Mourinho accepts apology over touchline row|
|Mourinho in furious bust-up with Chelsea staff after late equaliser|
|Chelsea 2 Manchester United 2: Barkley strike denies Mourinho|
|Raptors star Kawhi Leonard: Too early for MVP chants|
|WTA Finals 2018: Profiling the ´elite eight´|
|Cipriani sent off and facing ban for high tackle|
|Real Madrid 1 Levante 2: Lopetegui on the brink as abysmal run continues|
|Warriors coach Kerr: Jerebko ´one of us´ after game-winning tip-in|
|Real Madrid break record for longest goalless run|
|England wrap up ODI series in Kandy rain|
|Melbourne Victory 1 Melbourne City 2: Honda scores but suffers losing start|
|Mata starts for United as Chelsea boss Sarri selects Morata|
|Dovizioso prepared for another Marquez duel|
|Isco returns as Bale makes the bench for Real Madrid|
|Maddison feeling at home with Puel´s Foxes|
|Ruthless Australia beat Tonga in historic Test|
|Pep talks helped Mendy make the most of his time out of action|
|Wantaway Butler revels in boos|
|Emery: Arsenal must be calm with returning Koscielny|
|Sevilla don´t fear Messi or Barca – Kjaer|
|Conte, Zidane and the AC Milan contenders clouding Gattuso´s future|
|Koepka in control in South Korea, on track to become world number one|
|Dovizioso grabs pole at Motegi, Marquez sixth|
|Langer backs Marsh for ODI squad|