Ireland faced a significant task just to avoid the follow-on in its inaugural test match after being reduced to 95-8 by tea Sunday in its reply to Pakstan's 310-9 declared on the third day.
Joyce was 39 not out and Ireland captain Porterfield unbeaten on 23 at the close after they were both dropped off Mohammad Amir.
Former England one-day global Joyce, arguably Ireland´s greatest batsman and at 39 the oldest Test debutant since Australia´s Bryce McGain made his bow aged 36 in 2009, appeared to be a victim of the fact the Decision Review System was not being used in this match because Cricket Ireland had decided they could not afford the cost for a one-off game. The Pakistan opener could only get an edge to a rising delivery as William Porterfield gleefully held on to a comfortable catch at first slip.
Faheem, however, did have a break when, on 36, he edged Rankin only for a diving Niall O'Brien to miss the catch and give the obscured Gary Wilson at first slip no chance of taking the ball.
"We're confident, we can take a huge amount of confidence". Batting on 60, Shafiq hit a Rankin short-ball straight into the hands of square-leg as Pakistan went from 71-2 to 159-6.
The paceman took four wickets for 44 runs as Ireland's first innings was wrapped up inside 48 overs.
Abbas struck twice in a 30-minute spell before lunch to leave Ireland 5-3 after Sarfraz's well-timed declaration.
Former England one-day worldwide Joyce, at 39 the oldest Test debutant since Australia's Bryce McGain made his bow aged 36 in 2009, cashed in with some elegant shots including a cover-driven boundary off Mohammad Abbas.
LeBron James: Brad Stevens praise is overblown
The Raptors have homecourt advantage for the first time, and have lost just seven games at the Air Canada Centre this season. The Eastern Conference Finals kick off in Boston Sunday afternoon, while the Western Conference Finals will Monday night.
Ireland's maiden Test is not panning out the way newcomers would have hoped for.
Wilson, who came in down the order, helped ensure South Africa's 84 against England at Port Elizabeth in 1889 remained the lowest total by a side in their first Test-match innings.
Faheem responded to the arrival of the new ball, by stylishly driving Murtagh for four, having scored the fastest fifty by a Pakistan Test debutant, off 52 balls, on Saturday.
With it, Pakistan for the first time in 16 years enforced a follow-on.
Rankin, the former England global and only Irish player with test experience, had the honour of Ireland's first test wicket when Azhar Ali (4) edged him to second slip in the eighth over.
Abbas had lunch figures of two wicket for four runs and Amir one for one. It must be noted, after day one of the historic Test was washed out the follow-on option was changed from a lead of 200 runs to 150 as per the revised conditions.
Pakistan resumed on their overnight 268 for six.
Debutant Faheem Ashraf was dismissed for 83 and Shadab made 55 before the Pakistan bowlers ripped through Ireland, who restored some pride later in the day.
Imam, the nephew of Pakistan selection chief and former Test batsman Inzamam-ul-Haq, scored a hundred on his one-day worldwide debut against Sri Lanka a year ago.