South Africa ended day three of the third Test against Australia with a narrow 40-run lead but facing a difficult battle after Nathan Lyon removed captain Temba Bavuma late in the day at Newlands.

The Proteas were 140/4 at stumps on Thursday, with Matthew Breetzke unbeaten on 19 and Ryan Rickelton on eight.

They had recovered from early setbacks but lost two important wickets late in the innings to leave the match balanced in Australia's favour.

Australia had earlier been dismissed for 429, taking a 100-run first-innings lead after Josh Inglis scored a century and Alex Carey contributed 80.

South Africa lose momentum after Ackerman and Bavuma fight back

South Africa's second innings began badly when Mitchell Starc dismissed Aiden Markram early, before Josh Hazlewood removed David Bedingham to leave the hosts under pressure.

Marques Ackerman and Bavuma then steadied the innings, putting together a crucial partnership to rebuild South Africa's position. Ackerman made 62, continuing his strong contribution in a match in which he had also scored 95 in the first innings.

Starc broke the stand by dismissing Ackerman, giving Australia another opening. Lyon then removed Bavuma shortly before stumps, leaving South Africa with only a modest advantage and six wickets in hand.

The late breakthrough was important for Australia, who had worked hard to turn their first-innings advantage into a position from which they could challenge for victory.

Inglis century gives Australia the first-innings lead

Australia's total of 429 was built around a century from Inglis, who scored 102, and a patient 80 from Carey.

The pair helped Australia recover after South Africa had made inroads, with the visitors adding substantial runs during the middle and later stages of their innings.

Harmer finished with 4/104, while Jansen claimed 3/60 to lead the South African bowling effort. Jansen continued his impressive series, having also contributed with the bat earlier in the match.

South Africa had been dismissed for 329 in their first innings, leaving Australia with a 100-run advantage.

South Africa need a stronger start on day four

The Proteas will resume on day four with Breetzke and Rickelton at the crease, knowing they need to build a substantially larger lead if they are to put Australia under serious pressure.

With six wickets remaining, South Africa still have an opportunity to post a challenging score, but Australia's late strikes have left the hosts with little margin for error.

The third Test remains finely poised, with the next phase of South Africa's innings likely to be crucial in determining which side gains the upper hand.