Williams, watched over by her family in the stands, lost a tight first set before evening the match in the second at Center Court, the site of seven of her 23 grand slam titles.
She was a break-up in the third, but Tan showed her resilience by fighting back and taking a thrilling final set in a nail-biting tie-break.
When asked if it was the last singles match of her long, illustrious career, Williams said it was a question she “cannot answer.”
“Who knows where I’ll turn up?” she added.
On Tuesday, she made her long-awaited return to singles, a year after retiring from her last first round game at Wimbledon.
Momentum shifted between the two players over the course of the three-hour and 10-minute encounter – first in Tan’s favor as she improved the first set, then towards Williams as she rallied in the second.
It looked like the 40-year-old Williams would prevail in the deciding set as she served for the win, but the memorable return failed to materialize.
Tan broke back at 5-5, and despite failing to convert a match point at 6-5, she made no mistake when she got a second chance in the tiebreak.
As number 115 in the world, Tan played in her first game in the Wimbledon main draw and finished ninth in all grand slams.
“When I saw the draw, I was really scared,” she said after the game. “It’s Serena Williams – she’s a legend. I thought, ‘Oh my god, how can I play?’ And if I can win one or two games, that’s really good for me.”
Under the lights of Center Court, Tan comfortably did more than that: triumph against one of the greatest athletes the sport has ever seen.
“For my first Wimbledon — it’s wow. Just wow,” she added, struggling to find the words to capture her emotions.
It remains unclear whether this was Williams’ last appearance at Wimbledon. Asked to summarize her legacy during the tournament, she was concise, albeit understated.
“I think I’m pretty solid on the grass,” she said. “Maybe not today, but pretty solid out there.”
Nadal, Swiatek forward
In Tuesday’s previous matches at Center Court, there were victories for this year’s French Open champions Rafael Nadal and Iga Swiatek.
Nadal, a two-time Wimbledon winner, survived a scare to beat Francisco Cerundolo 6-4 6-3 3-6 6-4 as he began his pursuit of a 23rd Grand Slam title, while Swiatek recorded her 36th consecutive win by beating Jana Fett 6-0 6-3.
Nadal, who missed last year’s tournament due to injury, received a warm welcome at Center Court, where he was rigorously tested by Argentina’s Cerundolo.
The Spaniard looked on course for a routine win when he was 2-0 and a break-up in the third set, but the free-swinging Cerundolo fought back with a double break to take the set.
The game looked to be headed for a decision as the world No. 41 broke in fourth, only for Nadal to save his best for last and seal the win with a double break.
Swiatek, meanwhile, dominated the first set against Fett in her first game since the French Open, but had a rough patch in the second as Fett came close to a double break.
The breakaway recovered from the shaky start to the set and rattled five games in a row, boosting its winning run to 36 games.