JOHANNESBURG — Stuart Baxter was appointed coach of South Africa on Thursday, ending a long search that began when his predecessor was fired last year for misconduct.

Baxter will take charge of South Africa for the second time after coaching the team from 2004-05. His first stint ended after South Africa failed to qualify for the 2006 World Cup.

Baxter, a Scot, is coaching South African club SuperSport United and the South African Football Association had been in negotiations with the Pretoria-based team for weeks to secure his release.

Baxter will see out the South African Premier Soccer League before joining the national team, SAFA said.

The new coach's first task with Bafana Bafana is an African Cup of Nations qualifier against Nigeria in June.

That qualifier is just two weeks after his last scheduled league game with SuperSport but the national federation and club agreed to "work together" to ensure Baxter gets time to work with the South Africa squad in the lead-up, SAFA said.

Baxter, the former coach of England Under-19s and Finland, replaced Shakes Mashaba. Mashaba was fired in December after being caught on television after a game ranting about his treatment by the media. Mashaba also reportedly insulted senior SAFA officials in a separate incident at the same game and was fired after a disciplinary hearing.

Baxter is the latest coach to take on the heavy mantle of trying to turn around South Africa, which has underperformed badly over the last 15 years despite the country boasting the richest league in Africa, and despite it being the first African country to host the World Cup.

The 1996 African champion has made the quarterfinals of the African Cup of Nations just once since 2002, when it hosted in 2013. It failed to qualify for this year's African Cup and apart from 2010, it last qualified for a World Cup in 2002.

South Africa's game against Nigeria next month is its first in the final round of qualifying for the 2019 African Cup in Cameroon. The team is second in its four-team World Cup qualifying group after a win and a draw. South Africa needs to top that group to play at the World Cup in Russia next year.