The announcement ends months of speculation about his future and was accompanied by the news that longstanding sidekick commercial director Mike Coupe is to take charge.
But rattled investors still sent Sainsbury's shares down as much as 5.8% although they finished the day off 8.2p or 2.3% at 348.5p.
This cut the grocer's market value from £6.78 billion to £6.62bn.
Sainsbury's chairman David Tyler credited Mr King with overseeing "one of the most striking turnarounds in British retail history".
"In 2004, when he joined, Sainsbury's was close to being on its knees, its shelves were often unstocked, morale was at rock bottom, market share was falling and profits were wholly inadequate," he said.
Mr King has overseen a trebling in Sainsbury's profits although its share price has yet to regain the heights of near 600p it hit in 2007.
Mr Coupe faces a supermarket sector under growing pressure with customers' disposable incomes falling and growing competition from discount retailers.
Mr King said: "One of the challenges of a leader is to leave at a time when the business has the opportunity to go on to greater things in the future."
He said the business had been engaged in succession planning for the last three to four years and he had been attracted to the idea of a 10-year stint in the top job.
"I always had the idea of a two-term presidency as something that works well in politics and can work well in business."
Mr King will not take the £1.7m he could have received as a pay-off after the six-month transition period. But he will retain long-term incentive awards that could be worth millions of pounds.
Sainsbury's is Scotland's number four supermarket but UK-wide is now level pegging with Asda with a market share of 17% after continuing to put on sales growth in recent months as its rivals have faltered.
Some of this is due to Mr King's introduction of new ranges in clothing and general merchandise to the chain. It has also been rapidly growing its convenience store chain and online business.
After buying Lloyds Banking Group out of their Edinburgh-based Sainsbury's Bank joint venture, financial services has the potential to be another important area for the chain.
Aged 52, Mr King said yesterday he could yet do another big corporate job. "There is plenty of energy in this old dog yet," he said.
He has been linked with a role in Formula One racing, a claim he dismissed as "speculation".
However, any move to under-pressure Marks & Spencer is unlikely given an anti-compete clause that will keep him away from any of Sainsbury's rivals for 12 months after he leaves the business.
"I have not spoken to anybody about any job," he said.
Mr Coupe said his appointment is a story of continuity because he has worked alongside Mr King for the last decade.
"The reality of the market we are working in is that it has become more competitive than ever and that is a big challenge for the future," he said.
"The key pressure on the industry is the difference between household income growth and inflation where people are in relatively worse off than there were a few years ago."
Shore Capital analyst Clive Black said: "Whilst we express some disappointment that Mr King has decided to resign, continuity should present few shocks and surprises in the near term."
He warned that Mr Coupe, who previously worked at Iceland, Asda and Tesco, may have to deal with a resurgent Tesco, if the UK market leader regains its poise.
Professor Andre Spicer of Cass Business School said: "The appointment signals a wise gradual approach rather than a radical rupture.
"Too often outside appointments boost share prices in the short term, but implement generic strategies which do not fit their new company, damaging performance in the long term."
Mr King will leave after Sainsbury's investor meeting on July 9.