Hafnaoui competed in the 400 meter freestyle at the 2020 Summer Olympics in Tokyo, Japan where he placed first with a time of 3:43.36. He is only the third swimmer in history to win an olympic gold medal out of the 8th lane, the slowest qualifying lane. He also placed joint 10th in the 800 meter freestyle, missing qualification for the final.