CAIRO — Tunisia needed something to celebrate. And from the eighth lane of an Olympic swimming pool in Japan, Ahmed Hafnaoui delivered.

This summer, his country has been submerged in one of Africa’s deadliest ongoing coronavirus outbreaks, with overwhelmed hospitals experiencing dire shortages of supplies. The pandemic’s surge compounded existing stress, amid political and economic crises that have roiled the country for months.

Then, in 3 minutes 43.36 seconds, the underdog Hafnaoui — who also goes by Ayoub — dominated the 400-meter freestyle race, winning gold. He beat out Jack McLoughlin of Australia, who took silver, and Kieran Smith of the United States, who won bronze.

“I was in tears,” Hafnaoui, 18, said after his win. “When I see the flag of my country and I hear the anthem in the background, it was great. I’m so proud of it.”

For Tunisia, the win — paired with Mohamed Khalil Jendoubi’s silver medal in taekwondo — brought a temporary moment of reprieve to a country in crisis.

On social media, Tunisians celebrated the medals as a bright spot amid a difficult summer for the North African country.

“You are our oxygen and our vaccine against general depression,” Tunisian researcher Huda Mzioudet tweeted in response to a photo of the pair holding their medals. “Thanks for the euphoria. Many Tunisians woke up with a big hangover.”

“Thank you for this ray of hope in the middle of our dark night,” another observer wrote on Twitter.

The wins in Tokyo followed Tunisian tennis player Ons Jabeur’s remarkable appearance at Wimbledon this summer, when she became the first Tunisian and first Arab woman to make it to the quarterfinals. At the time, Nejmeddine Lakhal, the Tunisian ambassador to the United States, described her to The Washington Post as “a queen who is bringing happiness to the people of Tunisia during a very difficult time.”

Footage of the moment Hafnaoui realized he had won — in which he rips off his swim cap and goggles and whoops with glee — circulated widely on social media after the race. So did footage of his beaming coach celebrating in the arena and what appeared to be his family’s joyous watch party at home.

The recent successes of young people from Tunisia are helping keep people’s spirits afloat at home, said Eya Jrad, who teaches security studies at the Mediterranean School of Business in Tunisia.

“It’s about youth reclaiming their space,” Jrad said. “It’s given us so much hope.

“They are the product of that momentum that has been happening the last 10 years,” she said, referring to the years since the country’s 2011 revolution. “Right now, we don’t have anything . . . and people just want to see they actually can make it from nothing.”

Later Sunday, the country’s ongoing political crisis escalated. Tunisian President Kais Saied dismissed Prime Minister Hichem Mechichi and announced that parliament would be frozen for the next 30 days. He maintained his decision was constitutional.

Although some Tunisians took to the streets to celebrate the decision, Saied’s opponents decried the move as an attempted coup, including Rachid Ghannouchi, who leads the moderate Islamist party Ennahda and serves as speaker of parliament.

“I warn any who think of resorting to weapons . . . and whoever shoots a bullet, the armed forces will respond with bullets,” Saeid said Sunday.

As political uncertainty convulses his home, Hafnaoui will be preparing for another race in Tokyo — the 800-meter freestyle that begins later this week.

Claire Parker in Billings, Mont., contributed to this report.