Seven-time champion Williams went down to unseeded Tan 7-5, 1-6, 7/6 (10/7 in her first singles encounter since an injury forced her out of her first-round match at Wimbledon last year.
Williams, 40, won the last of her Wimbledon singles titles six years ago but reached the final in 2018 and 2019.
"I'm so emotional now," said Tan. "She's a superstar. When I was young, I was watching her so many times on the TV.
"For my first Wimbledon, it's wow – just wow.
"When I saw the draw, I was really scared. She's such a legend. I thought if I can win one game, two games, that would be really good for me."
Williams was far below her imperious best on Tuesday, struggling from the start with her form and fitness.
The 23-time Grand Slam singles champion, cheered by the crowd as she made her entrance, lost the first set but broke early in the second set and went on to level the match.
But she faltered while serving for the match and faded badly in the third-set tie-break after taking a 4-0 lead.
She finished with 61 winners but 54 unforced errors the 3-hour, 11-minute evening match.