South Africa’s last government of national unity was in 1994. It took four years of hard negotiations to put it together — and it lasted 24 months before former President Frederik Willem de Klerk’s party walked out in a huff from its union with Nelson Mandela’s African National Congress (ANC).

Mandela’s protege Cyril Ramaphosa, now South Africa’s president, and his opponents in the Democratic Alliance (DA) party had 12 days to strike a similar deal. On Friday, these weary rivals reached an agreement to create a new national unity government — though keeping it intact may be far harder than it was 30 years ago.

Yet, despite the peril that both parties now face internally and externally, their union was necessary to steer South Africa away from the economically disastrous, racially polarized, populist future that would have resulted if the ANC joined up with former President Jacob Zuma’s MK Party or Julius Malema’s Economic Freedom Fighters (EFF).

Faced with implosion, the country has perhaps once again defied the doomsayers and fashioned a centrist path ahead. Now leaders have to make it work — and awaken the moribund economy.

The ANC — which lost its majority in last month’s elections when its support plunged from 57% to 40% — and the centrist DA agreed to form a government with Ramaphosa as president. The DA would have representatives in the Cabinet and in the provinces of Gauteng and KwaZulu-Natal.

The deal freezes out the MK Party, which rejects the country’s constitution, and the left-wing, radical EFF from the levers of power. Signatories to the pact — including at least 10 smaller parties such as the Inkatha Freedom Party — will announce a policy agenda in six weeks.

The deal has numerous critics. Many within and outside the ANC and the DA want it to fail.

Since official negotiations began, senior ANC leaders and their key allies in trade unions and the South African Communist Party have accused the DA of protecting White interests and being aligned to South Africa’s apartheid past. On Friday, ANC leaders were being goaded by mainly EFF and MK Party supporters that they had signed a pact with their "supervisors.”

Activists for faster and more robust Black empowerment within the ANC, such as the Black Business Council, have cautioned against a coalition with the DA, arguing it would halt government efforts to promote Blacks in business and other walks of life. It is a debate that is likely to intensify, drive some Black support to the EFF and the MK Party, and perhaps even lead to a walkout by some leaders from the ANC. On Friday, the ANC was scrambling to assure its allies that the agreement would not sacrifice its policy positions on foreign affairs, affirmative action and workers’ rights.

The DA and ANC have destroyed coalition partners in the past. One of the key architects of the current deal, DA Federal Chairman Helen Zille, lured anti-apartheid icons Mamphela Ramphele and Patricia de Lille and their parties into coalitions in the 2010s — and promptly rendered them irrelevant. The ANC famously "merged” with the party of apartheid, the National Party, in 2004. The NP was dead in a couple of years.

Although it is termed a government of national unity, Friday’s agreement is really a grand coalition — two of the biggest parties (the DA got 22% of the vote) are coming together. Should they find the marriage intolerable, the other players in the unity government cannot maintain a majority — and the ANC may be forced into the arms of the EFF or the MK Party.

The consequences would be significant: Ramaphosa would be forced out, policy would become unstable and many of the economic reforms Ramaphosa has brought about would be stalled. Corruption, a key characteristic of the Zuma administration, would be enabled.

That is why a DA-ANC tie-up is such a necessary deal for South Africa. The challenge now is for Ramaphosa, after six years of lethargy, to double down on his reforms and act with speed and resoluteness to turn the economy around.

The ANC and the DA differ on many policies — minimum wage and worker rights, affirmative action, the Palestinian question — and yet have enough overlap to work together incredibly well on economic reform initiatives that would alleviate the country’s problems of unemployment, poverty and inequality. That will require cool heads, suspension of egos and partisan interests and commitment to building a better country.

For now, the mantra for the coalition partners should be simple: It’s the economy, stupid.

Justice Malala is a political commentator and the author of "The Plot to Save South Africa: The Week Mandela Averted Civil War and Forged a New Nation.”