The left-handed opener, who was spilt down the leg side by wicketkeeper BJ Watling on 36 shortly after lunch, brought up his century from 197 balls with his 20th boundary.
The 29-year-old finished on 128 not out and also combined with captain Faf du Plessis (52) for a 126-run partnership that resurrected his side’s innings after they had slumped to 22-3 in a difficult first session of the three-match series.
Temba Bavuma, who joined Elgar before tea when du Plessis was dismissed, was on 38 not out at the close.
Du Plessis was caught in the deep by Trent Boult off all-rounder Jimmy Neesham three balls after he had a leg before decision overturned on review.
The Proteas were rocked by the loss of three early wickets when left-arm seamer Neil Wagner claimed two victims in one over following du Plessis’s late decision to bat after winning the toss.
Du Plessis finally opted against bowling first when he noticed that New Zealand had dropped pace spearhead Tim Southee to play two spinners in Jeetan Patel and Mitchell Santner.
The visitors had been under pressure when they resumed after lunch on 63-3 and New Zealand could have driven home their advantage had Watling held on when Elgar got a thick edge in the second over of the session.
New Zealand had seized the early advantage when skipper Kane Williamson introduced Patel in the sixth over, with the off-spinner proving difficult to get away as he extracted bounce and turn off the pitch.
Paceman Boult then got a delivery to swing back into right-handed opener Stephen Cook, who offered no shot and was given out lbw for three to leave the hosts 10-1 in the ninth over.
Williamson then reintroduced Wagner and he struck immediately to remove the dangerous Hashim Amla for one.
Four balls later, he had JP Duminy caught at first slip by Ross Taylor, also for one, from a rising delivery that brushed a glove to leave the visitors in dire trouble.
Following the first test, the teams head to Wellington before concluding the series in Hamilton.
(Reporting by Greg Stutchbury; Editing by John O’Brien)