Substitute Daniel Alves scored off a free kick in the 88th minute to send Brazil into the final of the FIFA Confederations Cup with a nail-biting 1-0 win over host South Africa on Thursday.

Six minutes after entering the match in Johannesburg, Alves lined up for a blast from just a yard or two outside the penalty area. The FC Barcelona defender curled it expertly inside the right post to elude diving goalkeeper Itumeleng Khune.

“The game was very close so I put on a very quick player, a very aggressive player who is strong on set pieces,” Brazil coach Dunga said. “It was one of the few opportunities we were going to have. The foul was right in front of the goal area, so it was perfect for us.”

Brazil will play for the championship against the United States on Sunday (CBC, CBCSports.ca, 2 p.m. ET).

South Africa meets Spain for the bronze medal earlier Sunday (CBCSports.ca, 8:30 a.m. ET).

South African defence solid

Thursday’s contest had the making of a mismatch as it pitted the No. 5-ranked team in the world against 72nd-ranked South Africa. The Brazilians had beaten the U.S., Egypt and World Cup champion Italy to go a perfect 3-0 in a contentious Group B, while the South Africans went an underwhelming 1-1-1 to finish second behind Spain in the less-taxing Group A.

But in front of a boisterous and partisan Ellis Park crowd, the defence-minded South Africans executed superbly a game plan designed to put the clamps on a scary Brazilian attack that piled up a tournament-high 10 goals in the group stage — eight more than their semifinal opponent.

“We knew Brazil would have a lot of possession and we had to get players behind the ball,” South Africa defender Matthew Booth said. “But we had a go at them.”

Indeed, and to their credit, the South Africans didn’t sit back and play for a scoreless draw. Defender Aaron Mokoena had an excellent scoring chance in the 21st minute, breaking to the net with an eye on Teko Modise’s perfectly delivered free kick, but the header went too high.

Brazil’s big break

In the 29th, midfielder Siphiwe Tshabalala blistered a free kick right on target, but it didn’t curl enough and Brazil goalkeeper Julio Cesar used his mitts to deflect it away.

Star midfielder Steven Pienaar tested Cesar in the 44th, forcing the keeper to dive to his right to get a piece of the hard shot.

Brazil had its chances too, beginning with a drive by Ramires in the 12th minute that was corralled by Khune. Later in the half Kaka faked out a defender at the top of the penalty area, but his shot curled the wrong way and well wide. The Real Madrid midfielder also embarked on a dash along the right side, but his rolling attempt was easily handled by Khune at the goalpost.

The South Africans kept coming in the second half. Modise put another scare into Brazil when his shot hit a defender, crossing up Cesar. The keeper did well to dive back and get a hand on the ball.

The Brazilians, meanwhile, found it just as tough to generate offence as South Africa hustled to get men behind the ball whenever it lost possession.

Brazil’s big break finally came in the 87th minute when Mokoena brought down Ramires just outside the penalty area. Alves, who had replaced Albert Santos at defence in the 82nd, took his time lining up the free kick, his face a mask of concentration as he shuffled his feet. When Alves delivered, the shot was perfect — just out of the reach of Khune as it caressed the right post and settled into the mesh.

Yellow card for Alves

A jubilant Alves ran to the sidelines and doffed his shirt, pointing to a scripted tattoo on his chest. The display earned him a yellow card — Brazil’s third of the match after receiving none in the first three matches.

Brazil now faces a rematch against the U.S., which it blanked 3-0 in group play with goals from three different men. But that was before the Americans embarked on a miraculous run, beating Egypt 3-0 in the round-robin finale to earn an improbable semifinal berth, then stunning the soccer world with a 2-0 knockout victory over Spain on Wednesday.

“I didn’t watch the game last night because I was more concerned with the game today,” Dunga said. “We will watch that game tomorrow to prepare ourselves for the final.”

South Africa gets another crack at the Spaniards, who came away with a 2-0 victory when they met last week.