South Africa is to get rid of all pit latrines in state schools within two years after a five-year-old pupil drowned in a toilet in March.
"This is an initiative that will save lives and restore the dignity of tens of thousands of our nation's children," President Cyril Ramaphosa said.
Pit latrines are holes in the ground covered with a platform - and many are shoddily built.
More than 4,500 state schools in South Africa have pit latrines.
Lumka Mkhethwa's death in March in rural Eastern Cape province came four years after another five-year-old, Michael Komape, had also died after falling into a school toilet in the northern province of Limpopo.
The case in March led President Ramaphosa to launch an audit of sanitation facilities in the country's 25,000 schools.
The Sanitation Appropriate for Education (Safe) programme will be funded in partnership with private groups including the Nelson Mandela Foundation and the UN children's agency (Unicef).
"The Safe initiative reaches beyond the bricks and mortar of water and sanitation. It seeks to contribute to building a cohesive society in which schools are the heartbeat of wholesome communities," Mr Ramaphosa said.
The cost of the ambitious project is estimated at 6.8bn South African rand ($477m; £ 375m), says the BBC's Pumza Fihlani in Johannesburg.
This government estimate includes the demolition of existing structures as well as the building of proper toilets, our correspondent says.
South Africa's school pit latrines
- More than 4,500 schools have pit latrine toilets, out of almost 25,000 nationwide
- Many are made from cheap metal, are shoddily built and left uncovered
- Eastern Cape, KwaZulu-Natal and Limpopo provinces are among the worst, says Education Minister Angie Motshekga
- Eastern Cape has 61 schools with no toilets at all, and 1,585 schools with pit latrines
- Neighbouring KwaZulu-Natal province has 1,379 pit latrines in use
- Limpopo province, where Michael Komape went to school, has at least 932 unsafe toilets