For centuries, the dominant ethnic group in the country was the Malays but, under British rule, a huge wave of immigration from China and the Indian sub-continent reduced the Malays to only 60 per cent of the population. Almost all of the Malays were Muslim; few of the others were.
But the bigger problem was that the Malays ended up much poorer than the newcomers.
In 1969, there were bloody riots in Kuala Lumpur that killed hundreds of people and perhaps as many as 2000.
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. However, time passes and circumstances change.
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.
Anwar was dismissed from his post 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.
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, contrary to expectations, a court threw the charges out. "To be honest, I was a little surprised," Anwar said afterwards. Now he has emerged from that shadow, 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 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 their religion or ethnicity.
Gwynne Dyer is a London-based independent journalist whose articles are published in 45 countries.