Aiden Markram hit a defiant fifth-test century and narrowed South Africa's target to 151 runs on the last day of the second test against Pakistan on Monday.

Markram was unbeaten on 100 off 221 balls and Temba Bavuma was shaping up well on 44 as the Proteas reached 219-3 at lunch.

South Africa, in pursuit of a 370-run target, still has minimum of 65 overs and seven wickets still hand to level the two-match series after Pakistan won the first test by seven wickets.

Pakistan's Hasan Ali, right, celebrates with teammates after taking the wicket of South Africa's Rassie van der Dussen during the fifth day of the second cricket test match between Pakistan and South Africa at the Pindi Stadium in Rawalpindi, Pakistan, Monday, Feb. 8, 2021. (AP PhotoAnjum Naveed)

Pakistan's Hasan Ali, right, celebrates with teammates after taking the wicket of South Africa's Rassie van der Dussen during the fifth day of the second cricket test match between Pakistan and South Africa at the Pindi Stadium in Rawalpindi, Pakistan, Monday, Feb. 8, 2021. (AP PhotoAnjum Naveed)

Markram has batted just over five hours, and raised his first test hundred outside South Africa on the last ball before lunch when he pushed Fawad Alam to wide mid on for a single.

The 26-year-old Markram batted resolutely, hitting 12 fours and three sixes, as Pakistan struggled to get further inroads after striking early on the last day.

Fast bowler Hasan Ali’s (2-46) twin strike within the first half an hour had pushed South Africa to 135-3 after the tourists resumed on 129-1.

Pakistan's Hasan Ali, second left, and teammates react after third umpire given LBW out to South Africa's Faf du Plessis during the fifth day of the second cricket test match between Pakistan and South Africa at the Pindi Stadium in Rawalpindi, Pakistan, Monday, Feb. 8, 2021. (AP PhotoAnjum Naveed)

Pakistan's Hasan Ali, second left, and teammates react after third umpire given LBW out to South Africa's Faf du Plessis during the fifth day of the second cricket test match between Pakistan and South Africa at the Pindi Stadium in Rawalpindi, Pakistan, Monday, Feb. 8, 2021. (AP PhotoAnjum Naveed)

Rassie van der Dussen (48) was beaten by Hasan’s late swing off the third ball of the day and was clean bowled before Faf du Plessis (5) was trapped leg before wicket off a delivery which kept a bit low.

Van der Dussen laid a foundation of 370-run chase by adding 94 runs with Markram before he was undone by Hasan's reverse swing.

Du Plessis woeful series ended after the most experienced South African batsman could score only 55 runs in four test innings.

South Africa's Faf du Plessis, right, reacts while Pakistan's Hasan Ali, third left, celebrates with teammates after his dismissal during the fifth day of the second cricket test match between Pakistan and South Africa at the Pindi Stadium in Rawalpindi, Pakistan, Monday, Feb. 8, 2021. (AP PhotoAnjum Naveed)

South Africa's Faf du Plessis, right, reacts while Pakistan's Hasan Ali, third left, celebrates with teammates after his dismissal during the fifth day of the second cricket test match between Pakistan and South Africa at the Pindi Stadium in Rawalpindi, Pakistan, Monday, Feb. 8, 2021. (AP PhotoAnjum Naveed)

But Markram and Bavuma dug in against pace and spin by raising 84-run partnership at nearly three runs an over which has raised the Proteas hopes.

Pakistan, which had a 71-run first-innings lead, set up a target of 370 runs after it was bowled out for 298 in the second innings with Mohammad Rizwan scoring a century.

More AP sports: https://apnews.com/apf-sports and https://twitter.com/AP_Sports

Pakistan's Hasan Ali, center, celebrates with teammates after taking the wicket of South Africa's Faf du Plessis during the fifth day of the second cricket test match between Pakistan and South Africa at the Pindi Stadium in Rawalpindi, Pakistan, Monday, Feb. 8, 2021. (AP PhotoAnjum Naveed)

Pakistan's Hasan Ali, center, celebrates with teammates after taking the wicket of South Africa's Faf du Plessis during the fifth day of the second cricket test match between Pakistan and South Africa at the Pindi Stadium in Rawalpindi, Pakistan, Monday, Feb. 8, 2021. (AP PhotoAnjum Naveed)