A historic win at Malaysia's general election by the opposition alliance led by the country's former leader, Mahathir Mohamad, will likely send markets on a wild ride, although analysts said long-term prospects appeared encouraging.

Pakatan Harapan, the opposition coalition, had the support of 135 members of the 222-member parliament, Mahathir said at a press conference on Thursday. That exceeded the 112 seats needed for a simple majority, upsetting the incumbent Barisan Nasional coalition.

Uncertainty will likely be a focus in the short term for markets following the surprise result.

"The Malaysia election outcome is a huge upset, no pollster was expecting this. This upset ranks up there with Brexit and [the] Trump election," said Aninda Mitra, senior sovereign analyst at BNY Mellon Investment Management.

"The bottom line is that while a long-term fix of governance, institutions and public life is now in sight, near-term policy uncertainty will be high," Mitra added.

Among the issues feared by investors is "an unfamiliar change of government as Barisan Nasional has ruled since independence and potential for riots and/or a messy handover of power," Nizam Idris, head of foreign exchange and rates strategy at Macquarie Group, said in a note.