Dean Algar scored a hundred as South Africa recovered from a slow start to reach 229-4 at stumps on day one of the opening Test against New Zealand in Dunedin.
Proteas captain Faf du Plessis won the toss and opted to bat first at University Oval, where the Black Caps have never lost in seven appearances since 2008, and it looked to be a bad decision as the tourists slumped to 22-3 after 19 overs on Wednesday.
But Elgar wrestled the momentum back in South Africa's favour with his seventh Test century, having put on a 126-run stand with skipper Du Plessis (52).
Elgar made it to the close of play unbeaten on 128 alongside Temba Bavuma (38 not out) as the Proteas seek to extend their unbeaten record against New Zealand to 14 Tests - dating back to March 2004.
It was advantage New Zealand - amid a four-game winning streak - early in the day, despite losing the toss and being forced to bowl first.
Kane Williamson - who oversaw the country's 3-2 one-day international series defeat to South Africa last week - lost his sixth successive toss during South Africa's tour of New Zealand, but the Black Caps skipper was smiling when an error in judgement cost opener Stephen Cook (3) his wicket in the ninth over.
Cook thought Trent Boult's (1-44) delivery would hold its line but it angled in towards middle stump to trap the South African batsman lbw.
Williamson then made a bowling change and it worked wonders as Neil Wagner (2-59) claimed two wickets in one over.
Hashim Amla (1) was his first victim, struggling with his foot work and a hint of inswing saw Wagner knock over middle stump and JP Duminy (1) followed four balls later.
A straight delivery swung straight onto Duminy as the ball hit his glove on the way through to BJ Watling as the Proteas slumped to 22-3.
That brought Elgar and captain Du Plessis together and the duo combined to steady the ship in the middle.
That's the 50 for the skipper! Gutsy knock to bring up his 10th Test half century. Superb show of patience and attrition. SA 147/3 pic.twitter.com/Tm8iOOcrQz-- Cricket South Africa (@OfficialCSA) March 8, 2017
A 126-run stand was just what South Africa needed as Du Plessis brought up his 10th half-century before he was sent back to the pavilion by James Neesham (1-29) prior to the tea break.
Du Plessis top-edged a shot to square leg, where Boult completed a regulation catch to see the visitors 148-4.
Elgar carried on in the absence of Du Plessis in the final session, posting his ton off 197 deliveries as he teamed up with Bavuma to thwart the Kiwis.