The 33-year-old, India's most successful Test captain, took to Twitter to announce his decision a day after India's 2-1 series defeat in South Africa.
"It's been seven years of hard work, toil and relentless perseverance everyday to take the team in the right direction. I've done the job with absolute honesty and left nothing out there," Kohli said in his statement.
"Everything has come to a halt at some stage and for me as Test captain of India, it's now. There have been many ups and also some downs along the journey, but never has there been a lack of effort or lack of belief."
The feisty top order batsman has had a difficult relationship with the Indian cricket board (BCCI) since stepping down as the Twenty20 captain after last year's World Cup.
That cost him the one-day captaincy as well, with the BCCI installing Rohit Sharma as captain in both the short formats.
"It comes as a shock for everyone as he is one of the most respected test captains," former test batsman Ashok Malhotra told NDTV news channel.
"I think he jumped before he was pushed."
Kohli thanked Mahendra Singh Dhoni, whom he replaced as the Test captain in 2014, and former India coach Ravi Shastri in his statement.
Known as well for his passionate leadership as for his glorious cover drives, Kohli led India in a record 68 Test matches, winning 40 and losing 17 to be fourth in the list of captains with most test victories.
"BCCI congratulates #TeamIndia captain @imVkohli for his admirable leadership qualities that took the Test team to unprecedented heights," the Indian board wrote on Twitter.
BCCI officials were not immediately available to confirm who would take over as India's next test captain, although opener KL Rahul's name has already started doing the rounds.
India's next Test assignment is a two-match home series against Sri Lanka in February-March.
Under Kohli, India became the top Test nation and made it to the final of the inaugural World Test Championship last year, where New Zealand beat them to the title.
With him at the helm, India ended a 71-year drought when they registered their maiden series victory in Australia in early 2019.
His team also held a 2-1 lead in England last year before the final test in Manchester was postponed following a COVID-19 outbreak in the Indian camp.
Kohli led by example to change India's fitness culture and also oversaw the development of a formidable pace attack that was key to their success overseas.
"When Virat took over as Test captain, India winning a test overseas was an achievement, now if India lose an overseas Test series it is an upset," former Test opener Wasim Jaffer wrote on Twitter.
"And that's how far he has taken Indian cricket forward, and that will be his legacy."