Ding blundered at a key moment in Game 14. Gukesh cried while signing the score sheet as he won a battle of nerves.
Gukesh got 7.5 points as against 6.5 of Liren.
Earlier, Garry Kasparov of Russia was the youngest world chess champion when he won the title at 22.
He is the second Indian after Viswanathan Anand to win the title. Anand was a five-time world champion.