Image copyright Reuters Image caption Mr Najib has consistently denied allegations of corruption

Malaysia's top prosecutor has cleared Prime Minister Najib Razak of corruption in a long-running financial scandal that has gripped the nation.

The attorney-general's office said the $681m (£479m) that Mr Najib received in his bank account was a personal donation from the Saudi royal family.

Critics had alleged the money came from state-owned investment fund 1MDB.

Mr Najib has consistently denied these accusations, but has faced pressure to resign over them.

Anti-corruption officials have previously said he received money as a gift from a foreign funder.

Attorney-General Mohamed Apandi Ali said in a press statement on Tuesday that the amount was a "personal donation" from the royal family in Saudi Arabia, transferred between the end of March and early April 2013.

He added that anti-corruption officials had met witnesses including the person they identified as the donor to confirm it.

"I am satisfied that there is no evidence to show that the donation was a form of gratification given corruptly," he said, adding that evidence did not show the donation was used as an "inducement or reward" for Mr Najib to do anything in his capacity as prime minister.

Case that gripped Malaysia: Karishma Vaswani, BBC Asia Business correspondent

The case of the mysterious millions has in equal part enthralled and angered Malaysians.

Even after this decision many still have unanswered questions. In the first place, why did their prime minister need this personal donation? What was the money used for?

The attorney general said Mr Najib had returned $620m, but that begs the question - where did the other $61m go?

Leaders from Umno, Mr Najib's party, have claimed the donation funded party activities including the campaign for the 2013 election, but critics have alleged it was used to buy political support within the leadership and for Mr Najib's personal use.

Some Malaysians have pointed to the fact that the new attorney general is a recent appointment - replaced after Mr Najib kicked his predecessor out over this very same drama.

The scandal has cast an ugly shadow over Mr Najib's seven-year leadership. But this decision effectively clears him, which political analysts say will secure his position within his own party and the country for now.

Malaysia's 'mysterious millions' - case solved?

1MDB: The case riveting Malaysia

Media playback is unsupported on your device Media caption How Najib Razak has handled the scandal

Malaysia held its last general election in May 2013, which returned Mr Najib's party to power but with one of its poorest showings on record.

The attorney general also said no criminal offence was committed by Mr Najib in relation to three other related investigations and that no further action would be taken.

'A great surprise'

Mr Najib said the findings "confirmed what I have maintained all along, that no crime was committed".

He urged the country to "unite and move on", saying the controversy had been "an unnecessary distraction".

Opposition members, however, criticised the prosecutor's decision.

Lim Kit Siang, parliamentary leader of Malaysia's main opposition party, Democratic Action, told the BBC it came as "a great surprise... that the attorney general can exonerate the prime minister for the $680m scandal".

"Nobody would give that donation for nothing," he added, and said the attorney general had to provide more evidence to justify his decision.

Meanwhile, activist group Transparency International said several questions remained: "Where did it [the money] go and why was this personal donation made?"