South Africa have stretched out a useful 81-run lead over New Zealand in the second Test, hanging on grimly to finish the second day on 349-9 in Wellington.
Quinton de Kock and Temba Bavuma had seen the Proteas through to 218-6 at tea, but both fell early in the final session of the day.
However, Vernon Philander (36) and Morne Morkel (31) stepped up to construct a stubborn unbeaten 47-run last-wicket stand as the shadows lengthened.
Colin de Grandhomme returned figures of 3-52 to lead the Black Caps attack, Neil Wagner backing up with 3-96 while Tim Southee contributed 2-98.
Earlier, de Kock had looked well on target for his fourth hundred in 17 Tests after piling on 114 runs in a productive second-session partnership with Bavuma.
He was punishing on anything short, going into the tea break on 63 from 87 balls, and upping the tempo when play resumed, adding 21 runs in quick time.
But Jimmy Neesham struck a key blow for the Black Caps eight overs into the final session.
De Kock caught an edge as he chased a full delivery angling away, and wicketkeeper BJ Watling made no mistake in taking the regulation catch.
De Kock’s 91 came off 118 balls, and included 10 boundaries and three sixes.
It was a particularly impressive effort, given his last two stints had totalled just 14 in last week’s drawn first Test in Dunedin – both ended by Jeetan Patel, who had also dismissed him for six and 0 in the last two ODIs.
Bavuma was out for 89 nine overs later, mistiming a hook shot off a Wagner bouncer and skying an easy catch to Neesham running in from the deep.
De Kock and Bavuma’s 160-run partnership was crucial after South Africa lost 80-4 in an action-packed first session on Friday.
De Grandhomme grabbed a brace, with Southee and Wagner snaring a wicket apiece to leave the Proteas reeling at 104-6 at lunch.
Faf du Plessis (22) and Hashim Amla (21) were dismissed cheaply, joining JP Duminy (16) back in the pavilion early.
South Africa had begun the day on the back foot at 24-2 after losing openers Stephen Cook and Dean Elgar in a costly final seven overs on Thursday.