The national flag they play under no longer exists officially. The anthem they stand for at the beginning of every game belongs to a republic that was toppled two years ago.

Yet Afghanistan’s athletes have become the unlikely — and widely celebrated — heroes of the Cricket World Cup that is underway in India. In a tournament followed by hundreds of millions of people across the globe, they have defeated the defending world champions and two former titleholders handily. Some of the team’s stars are so popular that entire stadium sections roar their name. When they win, players sing and dance from the dugout, to the team bus, to their hotel rooms.

The Afghan cricket team’s accomplishments are amplifying what has already been an astonishingly speedy rise in sports history. They also speak to the potential of a nation marked by frequent violent ruptures if it had a little bit of what this team has managed: continuity.

To play in this World Cup, the team has relied on delicate compromise, something that evaded Afghanistan’s political leaders and the many international stakeholders who failed to halt the country’s descent into a pariah state. The bizarreness of the circumstances is drowned out by the team’s success.

“People are praying for us at home, they are sitting for our matches, for us to win, because cricket is the only happiness in Afghanistan,” Rashid Khan, 25, one of the team’s biggest stars, told his teammates in a pregame huddle ahead of a victory last week.

He emphasized getting the basics right. But he underlined what was most important: “The biggest thing — keep smiling.”

In a country stuck in a spiral of gloom, even small celebrations feel like acts of defiance.

Since the Taliban takeover two years ago, Afghanistan’s aid-dependent economy has crashed, leaving nine out of 10 people in poverty. Nature has added to the misery with earthquakes that have wiped out entire villages, killing hundreds of people.

The Taliban regime — which restricts women to their homes, denying them the right to work or to an education beyond the sixth grade — is a government that is not recognized internationally. Its white flag does not feature in international sports competitions. Afghan teams play under the banner of the republic that fell in 2021.

The national anthem that is played before every game is also a relic. The Taliban do not have an anthem of their own because they consider public music forbidden by Islam.

But the Taliban cheer the cricket team’s success, and officials say they have assisted the team in achieving its current success. Fans in Kabul, Afghanistan’s capital, and other cities pour into the streets in celebration after every victory, and the rulers release celebratory messages even as they ignore the black, red and green brandished by the players and fans at the stadiums, and the renditions of the anthem.

In this environment, the players walk a tightrope. Mr. Khan and another of the team’s stars, Mohammed Nabi, have set up foundations that provide aid to the needy, rushing to help after the recent earthquakes.

Both have issued statements calling for restoring girls’ education.

“We stand in solidarity with our sisters and daughters of Afghanistan in demanding that the decision on high school ban for girls and university ban for women be reversed,” Mr. Khan said in a statement last year. “Every day of education wasted is a day wasted from the future of the country.”

Cricket has risen to prominence in Afghanistan only in recent decades. Some of the country’s earliest players learned the game at refugee camps in Pakistan, after fleeing the Soviet invasion of Afghanistan. The earliest seeds of the game within the country date back to the last time the Taliban were in power in the 1990s.

A more formal setup was created in the early 2000s, and the team’s rise from there was nothing short of a fairy tale. In just about a decade, Afghanistan climbed through the ranks, and began qualifying for several global championships, including three World Cups.

“We learned cricket as refugees,” said Raees Ahmadzai, a former player who is the assistant coach of the World Cup team. “The new generation is our product. We trained them in Afghanistan.”

Winning the current competition, which is in the daylong version of cricket, remains a long shot for Afghanistan. But the journey of Mr. Khan, the team’s star, illustrates just how far Afghan cricket has come.

A decade ago, Mr. Ahmadzai said he and his teammates got a $3 monthly salary and a $25 daily allowance when they traveled.

Mr. Khan raked in $600,000 when he first started playing in the Indian Premier League, cricket’s most lucrative competition, in 2017, when he was 18. Last year, he was snapped up by a new franchise for nearly $2 million.

He is one of the most in-demand cricketers in the world, playing in leagues in Asia, Australia, the Caribbean and the United States as a bowler and batter. He has more than 13 million followers on social media. When he is on the field, a mere glance at the crowd elicits cheers and screams. When the Afghan team bus is on the road in India, motorcycle riders compete to pull up to his window for a wave or even a dangerous selfie.

During practice, when the team breaks for evening prayer, the team lines up behind Mr. Khan on a plastic mat rolled out in a corner of the stadium. When the team wins, he is the first to break into dance, leading the celebrations boombox in hand.

Mr. Khan’s pathbreaking celebrity has inspired an entire generation of younger players, some of them already playing at his side.

As the team traverses India for the tournament, a small band of supporters follows it, waving the old flag from the stands and dancing to D.J. music outlawed back at home. India has barred Afghans from entering the country since the Taliban takeover, making only rare exceptions. Those in the stands are longtime refugees, as well as many who went to India as students and are now stranded there.

After every match the team has won — first against England, the defending champions, then against Pakistan and Sri Lanka — the players have taken a victory lap around the stadium, thanking the Afghan fans and the thousands of Indian fans who cheer for them.

When the team defeated Pakistan two weeks ago, the celebrations were particularly long and loud. There was also a political undertone: In recent weeks, tens of thousands of Afghan refugees have been forced out by Pakistan, whose military has long been seen as contributing to the instability in Afghanistan.

To get to that game, one fan, Akhtar Mohammed Azizi, had taken a 10-hour bus ride.

“It was such a great moment that I forgot everything else — I could only think of positivity and happiness,” said Mr. Azizi, who has been stranded in India since completing his business degree. “I forgot the lack of sleep, the hunger. We celebrated, we danced, we took selfies with the players.”

During a break from celebrations, Mr. Ahmadzai, the coach, and Mr. Khan, the star player, recorded a video for their fans back at home. They recited a Pashto poem that has been the team’s rallying cry for years before returning to dancing — in the dressing room, on the bus, and late into the night in the team hotel.

“Pull up your sleeves, get in and dance/

The poor man’s happiness comes only now and then.”