Williams, watched by her family in the stands, lost a tight first set before equalizing in the second on Center Court, where she won seven of 23 Grand Slam singles titles.
In the third, she lost, but Tan showed her resilience by fighting back and winning a thrilling final set in a tiebreak.
Asked if this was the last Wimbledon match of her career, Williams said it was a question she “couldn’t answer”.
“Who knows where I’ll pop up?” she added.
She made a long-awaited return to singles on Tuesday, a year after she retired in her final first round match at Wimbledon.
Over the course of the three-hour, 10-minute meeting, the momentum between the two players reversed—first in Tang’s favor as she won the first set, then in favor of Williams as she rallied in the second.
The 40-year-old Williams looked set to win the deciding set as she served to win, but there was no memorable comeback.
Tan bounced back at 5-5 and, despite failing to convert a match point at 6-5, made no mistake when she had a second chance at the tie-break.
No. 115 in the world, Tang played in her first match in the Wimbledon main draw and ninth in all Grand Slams.
“When I saw the draw, I was very scared,” she said after the match. “This is Serena Williams – she is a legend. I thought, “Oh my God, how can I play?” And if I can win one or two games, that’s very good for me.”
Under the lights of Center Court, Tang comfortably achieved more, taking down one of the greatest athletes the sport has ever seen.
“For my first Wimbledon, it’s wow. Just wow,” she added, struggling to find words to express her emotions.
It remains unclear if this was Williams’ last appearance at Wimbledon. When asked to sum up her legacy at the tournament, she was brief, though understated.
“I think I’m pretty firm on grass,” she said. “Maybe not today, but it’s pretty solid there.”
Nadal, Svyatek go ahead
Tuesday’s earlier games on Center Court saw wins by this year’s French Open champions Rafael Nadal and Iga Swiatek.
Nadal, a two-time Wimbledon winner, survived the fear and beat Francisco Cerundolo 6-4, 6-3, 3-6, 6-4 as he started chasing his 23rd Grand Slam title while Swiatek recorded her 36th th win in a row, beating Jan Fett 6-0 6-3.
Nadal, who missed last year’s tournament due to injury, was warmly received on Center Court, where the Argentine Cerundolo put him to the test.
The Spaniard was counting on the usual win at 2-0 and a break in the third set, but the swinging Cherundolo bounced back with a double break and took the set.
It seemed that the match was approaching the decisive one, when the first racket of the world. 41 broke in the fourth, but Nadal kept his best until last and sealed the win with a double break.
Meanwhile, Swiatek dominated the first set against Fett in her first match since the French Open, but had to overcome a tough period in the second when Fett came close to making a double break.
The top seed bounced back from a shaky start to the set and went five games in a row, extending their winning streak to 36 matches.