"I announce my resignation from the post of prime minister", Hariri said in a speech broadcast from Saudi Arabia by the Al-Arabiya news network.
In comments directed at Iran, he said the Arab world would "cut off the hands that wickedly extend to it". President Michel Aoun, who was elected in October 2016 after more than a two-year presidential vacuum, is a close ally of Hezbollah.
His first stint as prime minister came in 2009 but was only slightly longer than his most recent, lasting just 19 months, and failing in 2011 after ministers aligned with Hezbollah resigned while Hariri was in Washington DC meeting the then-US President Barack Obama.
It was not immediately clear whether Hariri meant to return to Lebanon.
Under a power-sharing system that helped end Lebanon's 15-year civil war, the president must be a Christian, the prime minister a Sunni and the speaker a Shiite. Aoun must appoint the candidate with most support among MPs, who he is expected to consult in the coming days. "I have sensed what is being plotted covertly to target my life", Hariri said.
Hariri also drew a comparison between the political situation in Lebanon today and in 2005.
In his speech, Hariri suggested he feared for his life and said the climate in the country is similar to the one that existed before his father, the late prime minister Rafik Hariri, was assassinated in 2005. A United Nations-backed tribunal has charged five Hezbollah members over the killing.
Hariri's resignation was unprecedented in the way it was announced, in a televised address from an undisclosed location in Riyadh.More news: Taylor Swift Just Released a New Song "Call It What You Want"
In a statement, the presidential office said Aoun was informed by Hariri in a phone call of his resignation, adding that the president now awaits Hariri's return to Lebanon to clarify the circumstances of his resignation.
Saudi Arabia's Gulf Affairs Minister Thamer al-Sabhan said in a television interview that Hariri's personal security detail had "confirmed information" of a plot to kill him.
Hazem al-Amin, a Lebanese writer who follows regional affairs, said Hariri's resignation is "completely a Saudi step" that comes in the context of an global and regional atmosphere against Hezbollah and against Iranian influence in the region. Iran was sowing strife, destruction and ruin wherever it went and he accused it of a "deep hatred for the Arab nation".
BBC reports that Mr Hariri has made several visits in the past few days to Saudi Arabia, whose leadership is strongly opposed to Iran. Afterwards, Velayati described Hariri's coalition as "a victory" and "great success".
Hariri, speaking in a televised address from the Saudi capital, Riyadh, condemned Iran and its growing power and influence in the region.
Across the political spectrum, analysts and officials said the resignation ushered in new dangers.
"We can not afford to fight the Iranians from Lebanon", he told Reuters, advocating an approach of compromise with Hezbollah in Lebanon while waiting for regional circumstances to allow Saudi-Iranian dialogue.
Hariri's "repetition of unreal and baseless accusations... against Iran show that the resignation is designed to create tensions in Lebanon and in the region", said Iran's foreign ministry spokesman Bahram Ghassemi.