In 1969 there were bloody riots in Kuala Lumpur that killed as many as 2000 people.
The country was already growing fast economically (it has averaged 6.5 per cent annually for the past 50 years), and all the ethnic elites were terrified that more violence would kill the goose that was laying the golden eggs.
So they made new rules that would placate the angry Malay majority by giving them priority in employment, education, business and access to cheap housing and assisted savings.
Those rules are still in effect, and the National Front, Malay-dominated but embodying leading members of all communities, won eight successive elections because its "New Economic Policy" (which was really about race) was seen as the only formula for domestic peace.
But time passes and circumstances change. Malaysia is now a middle-income country where differences in income and education between the various ethnic groups have narrowed considerably.
The National Front, after so long in power, has spawned a multitude of corruption scandals. And then along comes a Muslim, part-Malay politician who threatens the status quo.
Anwar Ibrahim began as a student leader demanding an even more privileged place for Malays and Muslims in Malaysia, but he has travelled a long way since then.
Mahathir Mohamad, the autocratic prime minister who ruled from 1981 to 2003, picked him as a potential successor and rapidly promoted him to deputy prime minister, but then in the late 1990s they fell out.
Their quarrels were over issues like Mahathir's toleration of corruption, but the basic problem was that Mahathir did not tolerate dissent.
Anwar was dismissed as deputy prime minister in 1998, and immediately afterwards was charged with corruption and sodomy. The aim was not only to jail him but to discredit him in the eyes of pious voters.
Anwar was jailed in 1999, but his sodomy conviction (based on highly implausible evidence) was overturned by Malaysia's Federal Court in 2004. Having served five years on the corruption charge, he returned to politics, but now as the leader of the People's Alliance, an improbable coalition of Islamic, Malay nationalist and ethnic Chinese parties.
And in the 2008 election, the People's Alliance won one-third of the seats in Parliament.
So Anwar was immediately charged with sodomy again. Even fewer people believed it this time, and a week ago, quite contrary to expectations, a court threw the charges out.
"To be honest I was a little surprised," Anwar said afterwards. And now he stands a good chance of winning the election that must be held this year or next.
Thirty per cent of the voters are undecided, and at least half the seats in the country are up for grabs.
If the People's Alliance wins, it will be because Malaysians of all ethnic groups believe that the "New Economic Policy" (which could be called the "New Ethnic Policy") is an outdated relic that facilitates corruption, and prefer a government that treats all Malaysians the same regardless of religion or ethnicity.
Then Anwar and everybody else will find out whether the country has really outgrown its ethnic obsessions.
Gwynne Dyer is a London-based independent journalist whose articles are published in 45 countries.