The 33-year-old, who stopped leading India’s limited-overs sides last year, had led the Test side since 2015.
He captained India in a record-breaking 68 Tests, winning 40 matches – the fourth best record of any Test captain in history.
“It’s been seven years of hard work, toil and relentless perseverance every day to take the team in the right direction,” Kohli said on social media.
“I’ve done the job with absolute honesty and left nothing out there. Everything has to come to a halt at some stage and for me as Test captain of India, it’s now.”
Kohli’s announcement came a day after India’s seven-wicket loss to South Africa in Cape Town, consigning the visitors to a 2-1 series defeat.
He has played in 99 Tests in total, averaging 50.39 in the longer format, with 27 centuries.
In 2021 Kohli led India to the the final of the inaugural World Test Championship, losing to New Zealand in Southampton.
“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,” he added on Twitter.
“I have always believed in giving my 120% in everything I do, and if I can’t do that, I know it’s not the right thing to do.
“I have absolute clarity in my heart and I cannot be dishonest to my team.”
Kohli’s major wins as captain included victory over Australia in 2018-19 – India’s first series win down under and one that Kohli at the time described as the “proudest” moment of his career.
He also captained India to a 2-1 away series lead over England last summer, before the final Test at Old Trafford was called off due to Covid-19. It has now been rescheduled for Edgbaston this July.
The Board of Control for Cricket in India (BCCI) congratulated Kohli and said he had taken the team to “unprecedented heights”.
Kohli paid tribute to his team-mates including MS Dhoni, who he took over from as Test captain.
“I want to thank the BCCI for giving me the opportunity to lead my country for such a long period of time and most importantly to all the team-mates who bought into the vision I had for the team from day one and never gave up in any situation,” he wrote.
“You guys have made this journey so memorable and beautiful.”
He added: “Lastly, a big thank you to MS Dhoni who believed in me as a captain and found me to be an able individual who could take Indian cricket forward!”
Former all-rounder Ravi Shastri, who was India head coach from 2017 until last year, said Kohli could step down with his “head held high”.
“Few have achieved what you have as captain – definitely India’s most aggressive and successful,” he said.
“Sad day for me personally as this is the team we built together.”
Kohli was also appointed limited-overs captain in 2017. He stepped down as T20 captain after the World Cup in November 2021, replaced by Rohit Sharma.
He was then removed as India’s one-day captain in December because selectors did not want two different white-ball skippers. (Courtesy BBC)