Considered the rank outsider in the men's 400m freestyle final, the youngster had no pedigree coming into his debut Games - his best finish at a major competition being eighth place at the Youth Olympic Games in 2018.
An incredibly tight race between all eight competitors came down to a duel between Hafnaoui and Australia's Jack McLoughlin for the gold, with the Tunisian finishing 0.16s ahead with a final time of 3:43.36.
"I just can't believe it, it's amazing," he told NBC afterwards. "I felt better in the water this morning yesterday and that's it - I'm Olympic champion now!"
Team USA took the final spot on the podium, with 21-year-old debutant Kieran Smith earning bronze to notch up the third medal in the pool for his country.
Hafnaoui, meanwhile, has another opportunity to put himself in the history books when he takes on the 800m distance starting on Tuesday.
> Tokyo 2020: Medal table in full body check tags ::