Malaysian prime minister Najib Razak’s long-ruling coalition clung to a slight lead in vote counting from Wednesday’s election, a cliff-hanger contest against a resurgent opposition alliance led by 92-year-old former leader Mahathir Mohamad.

However, Mr Najib’s Barisan Nasional (BN) lost seats in key states that have traditionally been strongholds, raising the prospect that it could be voted out of power.

Five hours after polling stations closed, BN had won 24 of parliament’s 222 seats and the opposition Pakatan Harapan (Alliance of Hope) had 17, according to unofficial results reported by state news agency Bernama.

BN faced a far greater challenge in this election than ever before amid public anger over the cost of living and a multibillion-dollar scandal that has dogged Najib since 2015. An election-eve opinion poll suggested that support for BN was slipping and Mr Mahathir’s alliance would land the most votes in peninsular Malaysia, home to 80 per cent of the population in this Southeast Asian nation.

However, under Malaysia’s electoral system, the party or alliance with the majority of parliament seats wins, and going into the poll most experts believed that was within the prime minister’s reach.

Malaysian prime minister Najib Razak of Barisan Nasional (National Front) and his wife Rosmah Mansor show their ink-stained fingers after voting in Pekan, Pahang. Photograph: Athit Perawongmetha/Reuters

The opposition claimed the contest would be skewed by a revision of electoral boundaries and a decision to hold the poll midweek, which it said would discourage millions from voting. The election commission and government dismissed the charges.

The commission said that 69 per cent of the roughly 15 million registered voters had cast their vote by 8am Irish time, two hours before polls closed. About 85 per cent voted at the last election in 2013.

Former Malaysian prime minister and opposition party Pakatan Harapan candidate Mahathir Mohamad (92) after voting in Alor Setar. Photograph: Jewel Samad/AFP/Getty Images

Voters complained on social media groups of long queues outside polling centres, which resulted in a waiting time of up to three hours for some. Opposition leaders had called for voting hours to be extended. Most results are expected before midnight (5pm Irish time) but the count may spill into the early hours of Thursday.

Mr Najib, casting his vote, said he was confident of victory following what he described as “quite vicious” personal attacks during the campaign. Leaders from both sides claimed earlier that their communications were being disrupted by non-stop spam calls on their mobile phones as voting progressed.

The Malaysian Communications and Multimedia Commission said in a statement that an initial investigation pointed to anonymous bot (automated programme) attacks from various sources and on various targets irrespective of political parties. – Reuters