Li emerged a 4-1 winner from a tense and tetchy encounter in which the favourite Ding was put through the emotional wringer after she was punished with three penalty points that left her railing at Italian official Paola Bongelli.
"I didn't do very well today. I had an obstacle and not only from the opponent but from the judge," Ding said, trying to choke back the sobs.
Serve penalties are a rarity in table tennis, but Ding was penalised twice for not throwing the ball up vertically.
After the second penalty at 7-2 down in the fourth, she walked away from the table exasperated, and received a red card and a third penalty point for towelling herself down at the wrong moment in the match.
Unflustered, Li kept her cool and finished off her opponent 11-8 14-12 8-11 11-6 11-4 after 51 minutes of high-octane action.
"This is the best I have ever played," the 24-year-old Li said after stepping onto the podium to have the gold medal hung around her neck.
"I am very excited. This has been my dream since being a little girl. I dreamed of being an Olympic champion, we are the same level, but today I performed better than expected.
"My family are in China. I want to thank my parents. They have sacrificed a lot to make my dreams come true."
She sung along with the national anthem and waved to the crowd as she received her medal while the clearly upset Ding stood motionless on the platform.
The world number one and current world champion wears her heart on her sleeve and could not contain her feelings as all eyes focused on her.
"I tried to change the situation, our levels are really close we both have the ability to win, and for that reason, I got affected by the judge," Ding added.
"At first I was trying to hold it together but after the second penalty I could not hold it down anymore."
International Table Tennis Federation president Adham Sharara tried to console Ding, congratulating her on her silver medal before saying he hoped the 22-year-old would return to win gold in Rio in four years time.
"She felt that the umpire was too strict on her and this happens sometimes," he said. "The umpires can be very strict and the players should adapt.
"When two players from the same country play each other, the umpire should be a little bit more lenient.
"If I was the umpire I would have been maybe a little bit more flexible."
The arguments overshadowed an enthralling final that pitched the two top seeds together in an all-Chinese encounter that ensured the Asian nation would maintain its stranglehold on the women's singles title.
China has now won all seven women's individual golds since table tennis was introduced to the Games in 1988.
Ding looked nervous early on and was quickly under pressure as Li yelped and fist pumped with every crunching forehand she sent scorching past her opponent.
A forehand crosscourt brought-up match point and when Ding sent the next one long, Li was running to the crowd to collect a Chinese flag to continue the celebrations.
Earlier in the day, Singapore's Feng Tianwei won the bronze medal match, beating Japan's Kasumi Ishikawa 4-0.
- Related links