"I cannot be prime minister if I cannot make the best decisions for the people. I have decided to step down from my post," Abe, 65, told a news conference.
Abe has battled the disease ulcerative colitis for years and two recent hospital visits within a week had fanned questions on whether he could stay in the job until the end of his term as ruling party leader, and hence, premier, in September 2021.
As news of the resignation spread, Japan's benchmark Nikkei average fell 2.12% to 22,717.02, while the broader Topix shed 1.00% to 1,599.70. The selling wiped $4.7 billion off Tokyo's $5.7 trillion stock market value, which had more than doubled during Abe's tenure.
The resignation will trigger a leadership race in the ruling Liberal Democratic Party (LDP) - most likely in two or three weeks - and the winner must be formally elected in parliament. The new party leader will hold the post for the rest of Abe's term.
Whoever wins the party poll is likely to keep Abe's reflationary "Abenomics" policies as Japan struggles with the impact of the novel coronavirus, but may have trouble emulating the political longevity that may be Abe's biggest legacy.
"The broad picture remains in tact. In terms of economic and fiscal policy, the focus remains very much on reflation," said Jesper Koll, senior adviser to asset manager WisdomTree Investments.
"Longevity will be a struggle."
On Monday, Abe surpassed a record for longest consecutive tenure as premier set by his great-uncle Eisaku Sato half a century ago.
"As head of the ruling party he worked hard on Abenomics for eight years," said brokerage employee Naohito Kojima, 55.
"There were various problems but if someone else had been leader, it's questionable whether they could have maintained a stable government as long as Mr Abe. He did various diplomatic negotiations and I think the pros outweighed the cons."
Abe's resignation also comes amid an uncertain geopolitical environment, including an intensifying confrontation between the United States and China and ahead of the U.S. presidential election in November.
FALLING SUPPORT
The conservative Abe returned as prime minister for a rare second term in December 2012, pledging to revive growth with his "Abenomics" mix of hyper-easy monetary policy, fiscal spending and reforms. He also pledged to beef up Japan's defences and aimed to revise the pacifist constitution.
Under fire for his handling of the coronavirus and scandals among party members, Abe has recently seen his support fall to one of the lowest levels of his nearly eight years in office.
Japan has not suffered the explosive surge in virus cases seen elsewhere, but Abe had drawn fire for a clumsy early response and what critics see as a lack of leadership as infections spread.
In the second quarter, Japan was hit by its biggest economic slump on record as the pandemic emptied shopping malls and crushed demand for cars and other exports, bolstering the case for bolder policy action to avert a deeper recession.
Abe kept his promises to strengthen defences, boosting spending on the military after years of declines and expanding its capacity to project power abroad.
In a historic shift in 2014, his government re-interpreted the constitution to allow Japanese troops to fight abroad for the first time since World War Two.
A year later, Japan adopted laws scrapping a ban on exercising the right of collective self-defence or defending a friendly country under attack.
But Abe proved unable to revise the U.S.-drafted, post-war constitution's pacifist Article 9, a personal mission that also eluded his grandfather, Nobusuke Kishi, who quit as premier in 1960 because of uproar over a U.S-Japan security pact.
Abe resigned from his first stint as prime minister in 2007, citing ill-health after a year plagued by scandals in his cabinet and a huge election loss for his ruling party. He had since kept his illness in check with medicine that was not previously available.