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.
|Noble contract extended to 2021|
|Split with Sky is an opportunity, says Brailsford|
|Van der Burgh rolls back the years, two more medals for Hosszu|
|Maitland-Niles praises Sterling for speaking out|
|Life is tough for him right now - Celtic striker Griffiths to take time away from football|
|Froome: Team Sky keen to continue with new partner|
|Emery confirms Koscielny to play against Qarabag|
|Llorente keen on Athletic return|
|I love the guy - Pocock backs under-pressure Cheika|
|Fit-again Ozil in line for Arsenal return against Qarabag|
|Raheem Sterling named Premier League Player of the Month|
|Two more Ligue 1 games postponed due to unrest|
|Pace attack among India´s best ever - Arun|
|Premier League has fostered ´excessive aggression´ among fans, says Scudamore|
|Sharks back Flanagan amid NRL investigation|
|Not good for my recovery! Hoddle delights in Spurs´ Champions League heroics|
|Harris backing Starc to fire in Perth|
|No fears over Atleti´s second-place finish for Simeone|
|Clippers buckled under Raptors pressure - Rivers|
|Icardi: Inter deserved to qualify|
|Team Sky future unclear as Sky opt to end involvement in cycling|
|PSG had to change mentality - Thiago Silva|
|Rockets make change, pick up win over Trail Blazers|
|Everything´s easier when you´ve got Messi – Miranda|
|From George Cross to Arsenal – Montemurro´s rise to make Gunners great again|
|Koulibaly challenges Napoli to win Europa League|
|Raptors star Leonard out against Clippers, may miss matchup with Warriors|
|Butler opens up about heated Timberwolves practice|
|Spurs achieved ´mission impossible´, says Pochettino|
|Dembele stunner pleases Barca boss Valverde|
|Van Dijk lauds ´fantastic´ Alisson|
|Van Dijk´s tackle on Mertens worthy of red card – Ancelotti|
|Klopp ´would have paid double´ for Alisson|
|Klopp: I don´t care about Madrid revenge mission|
|Tension and anxiety got to Inter, laments Spalletti|
|Tuchel hails magnificent PSG as Red Star win seals last-16 spot|
|Mbappe admits frank discussions inspired PSG´s Champions League progress|
|Klopp: Napoli had no answers to outstanding Liverpool|
|Pochettino proud of ´massive, massive achievement´ for Spurs|
|Barcelona equal Champions League record|
|Composed and controlled Liverpool see off Napoli to progress|
|Tenerife back to winning ways, AEK beat Hapoel|
|Howedes ´hurt´ after emotional Schalke return ends in defeat|
|Kane ´buzzing´ over ´not bad´ draw at Barcelona|
|Robertson hails Alisson´s ´unbelievable´ save as Liverpool progress|
|Red Star Belgrade 1 Paris Saint-Germain 4: Neymar brilliance helps secure Group C top spot|
|Inter 1 PSV 1: Icardi header not enough for the Nerazzurri|
|Liverpool 1 Napoli 0: Superb Salah sends Reds through|
|Club Brugge 0 Atletico Madrid 0: Simeone´s men miss out on top spot|
|Barcelona 1 Tottenham 1: Lucas rescues Spurs late on to secure progress|
|Monaco 0 Borussia Dortmund 2: Guerreiro double snatches top spot from Atletico|
|Butler´s groin strain ´nothing significant´ – 76ers coach Brown|
|Woakes, Curran among leading lights at IPL auction|
|Blue Jays release five-time All-Star Tulowitzki|
|Mourinho: Professionals care more than the fans|
|Casillas reaches 100 Champions League wins|
|Expansion franchise Cincinnati sign Garza, send Kamara to Rapids|
|Manchester City sign United States goalkeeper Steffen for reported £7m|
|Schalke 1 Lokomotiv Moscow 0: Russians miss chance for Europa League reprieve|
|Galatasaray 2 Porto 3: Terim´s men into Europa League after penalty drama|
|Jackman leaves Dragons role|
|Tottenham boosted as Barcelona bench Messi|
|Mane and Henderson in Liverpool XI to face Napoli|
|Mourinho shoots down question over how to get the best from Pogba|
|Ronaldo to start as Allegri aims to avoid Champions League big guns|
|Odriozola: I´m in love with Benzema, he´s the best number nine in the world|
|Vikings fire OC DeFilippo after loss to Seahawks|
|Marcelino suggests Valencia open to Batshuayi departure|
|Bottas to make rally debut in title-winning M-Sport Ford Fiesta|
|Kovac dismisses Pavard speculation|