After three hours and 34 minutes at the crease, in a vacuum of concentration to contend with the opposition attack and a show of stamina against heat and humidity, only one thing mattered to Dean Elgar: he had won a bet.

South Africa's video analyst, Prasanna Agoram, would need to get himself a razor blade. Fast. The agreement between the two was that if Elgar scored a century, Agoram would remove his moustache. In the moments after Elgar became the first South African opener to score a century in Sri Lanka, that was what he thought of.

Of course there was the roar, the relief. There were the fist pumps and the raised arms, the smiles and the soaking in of the moment. And then Elgar put his finger to his top lip, ran it across the outline and pointed to the change room. He smiled too, so Agoram may have thought he'd get away with a trim instead of a close shave but there was no chance. Elgar confirmed afterwards it would have to be "all off," and he made the deal because, "I don't think people enjoyed that moustache of his".

The moustache had been under threat right from the time Elgar began his innings. Everything about it - the cautious start, confident follow-through, severe treatment of full or length balls on or outside his off stump and a careful attention not to fall into a pressure trap - showed he understood the magnitude of the task ahead and knew how to manage it. In effect, he showed both the technique and the temperament required of an opening batsman in a Test match, which was what South Africa needed following the retirement of Graeme Smith.

The care Elgar took in the first few overs was exactly the kind of vigilance expected of him, especially after three months without so much as middle practice. Elgar took the two months after the South African summer to have a complete layoff and then returned to training with his new franchise, the Titans, and had a session with the South African camp in Pretoria in the lead-up to the series. But actual time at the crease? He has had none since early April and he knew he would require a measured opening to allow himself time to find his touch.

Elgar's first shot in anger was off a full, wide delivery offered up by Shaminda Eranga. That was in the eighth over, when he also took Eranga for two more boundaries, which allowed him to settle. "There was one over I faced where I took Eranga for three boundaries," Elgar said. "Before that I was sedate but sometimes one over gets you into another gear."

It should have also told Sri Lanka where not to bowl to Elgar. In total a shade fewer than a third of his runs, 33, came off full deliveries outside the off stump and another 45 runs from good length balls either on the stumps or outside off. Perhaps they were wary of testing him with short-of-a-length ball because of how keen he was to stay in his crease and on the back foot.

Later in the session damp towels appeared. Du Plessis lay fully stretched out on the floor, as though he was taking a brief nap, but Elgar only squatted onto his haunches - down but not out

Where Elgar showed some vulnerability was in his footwork against spinners but he countered any sluggishness with sharp focus that ensured his defences were not breached. Elgar's intense attention to detail ensured that when Rangana Herath or Dilruwan Perera tried to draw him forward with flight, he resisted with a block. With his intent to play as late as he could, there were occasions when Elgar was hurried into his strokes. He seemed to mind that less than the prospect of being overeager and mistiming.

That was particularly important after lunch when runs dried up and Faf du Plessis batted as though there was a Test to save. In 15 overs after the break, South Africa scored just 35 runs and their run-rate stalled from close to four an over to barely over 2.5. Herath and the two seamers effected the stranglehold and it would have been easy for Elgar to have a lapse in his application.

If he had, given the wearing conditions, it may have been spoken about as understandable. That he did not speaks to his ability. The weather took its toll on Elgar as his innings progressed. In the post-lunch drinks' interval, South Africa's support staff brought out umbrellas for the first time in this series. Even a few moments of shade can provide some relief. Later in the session damp towels appeared. Du Plessis lay fully stretched out on the floor, as though he was taking a brief nap, but Elgar only squatted onto his haunches - down but not out.

He offered one half-chance when he was on 91 and lured into a false shot by Herath and flicked the ball between the two men at midwicket. And then he realised things were getting much tougher. With the ball getting softer and turning in a way "it's supposed to on day one," according to Elgar, he began to wonder how much longer he'd manage to hang around.

He faced nine more deliveries before teeing off to bring up his second Test century in the same fashion as he achieved his first. He went down the track and lofted the ball straight down the ground. Six and a hundred. "I was a little bit scratchy in the 90s," he said. "It was a premeditated moment. It paid off."

Tea came shortly after that and so did Elgar's wicket, prompting the Sri Lankan fightback and proving that probing, patient bowling was the only way to get anywhere on this track. But that should not detract from the message Elgar sent out.

That he has the talent it takes to perform on the international stage has been known to followers of South African domestic cricket since the 2006 Under-19 World Cup. Then, he was South Africa's highest run-scorer and fourth on the overall list. What needed more confirmation was whether Elgar had the temperament to play at the highest level.

A century on a pitch that has been described as being flatter than a regular Galle pitch, which is pretty flat anyway, and an attack of which a little more was expected upfront is not conclusive proof of that. But it's a good enough start and one Elgar can be sure has made him win a lot more than just a friendly wager.

Firdose Moonda is ESPNcricinfo's South Africa correspondent