ISLAMABAD, Pakistan — Ammar Barlas was prepared for disappointment. He is Pakistani, which — almost by default — makes him a cricket fan. And Pakistan was preparing to play India, its hated but heavily favored rival and a team it had not defeated in the sport’s World Cup tournament in nearly 30 years.
Still, a fan supports his team, and Mr. Barlas, 35, prepared a special dish of chicken and rice and invited his college buddies to watch the inevitable.
“The get-together of the friends was meant for the enjoyment of the game, but we were also mentally prepared for a loss,” Mr. Barlas said. He added, “We were feeling anxious but kept repeating the sentence, ‘First of all, you don’t have to panic,’” referencing a phrase popularized by Pakistan’s prime minister, Imran Khan, who was once a cricket star.
Pakistan averted defeat. It unexpectedly beat India on Sunday night in Dubai, advancing to play New Zealand on Tuesday evening — it won that match, too — and giving the nation a much-needed boost that lingered even two days later.
With an ailing economy, bitter political discord among the ruling and opposition political parties, militants rearing their heads in some parts of the country, and turbulent relations with the United States and several European countries, Pakistan sorely needs a feel-good moment.
“In a country where cricket is almost a religion and good news — sporting or otherwise — has been hard to come by in the recent past, the victory was a much-needed reason to celebrate,” read an editorial in The Express Tribune on Tuesday.
The win united the nation, enveloping it with a sense of national pride. Cricket binds the country. It is perhaps the only legacy of British colonialism that is neither contentious nor despised. Instead, cricket stirs passions and transcends ethnic, linguistic and political divides.
The victory over India set off celebrations that carried on long into Sunday night. The whole country was transfixed on the live match, which was aired in restaurants and cafes. Streets and shopping centers were mostly deserted from 7 p.m. to 11:30 p.m.
After the win, people young and old poured out onto the streets, honking horns, setting off big rounds of firecrackers and breaking into Bhangra moves in several Punjabi cities and towns. Many even resorted to aerial firing (which is illegal, but no one seemed to care Sunday night). The green flag of Pakistan was raised with pride.
Immediately victory memes went viral on the country’s WhatsApp groups, and one video on Instagram of a newlywed couple was widely shared. In it, the groom stands up as soon as the wedding hall receives the news of Pakistan’s win and starts chanting, “Long live Pakistan!” He is quickly joined by other guests.
On his Twitter account, Mr. Khan, the prime minister, who was visiting Saudi Arabia over the weekend, posted a photograph of himself watching the match in a hotel suite, surrounded by cabinet ministers, with a message: “The nation is proud of you all.”
Sheikh Rashid Ahmed, the interior minister, said he had ordered the removal of police barricades and blockades on the roads in Islamabad, the capital, and some parts of Punjab so that the public could celebrate. The police had taken preventive measures last week to stop a protest of a religious party from marching toward Islamabad.
On Monday, the country’s newspapers carried stark headlines and pictures of the cricket team on their front pages. Pakistan “vanquished” India, one English daily declared. Jang, the country’s leading Urdu newspaper, described the win as “historic,” a sentiment echoed by other major Urdu newspapers.
Saba Usman, a teacher at a private school in Islamabad, said her fifth-grade students were overjoyed the next morning. “The children couldn’t stop talking about the game and kept praising Pakistani players,” she said. “Some of my students said they couldn’t sleep out of happiness.”
Pakistanis who are not fans of cricket also felt elated. “The win was an excuse to dance and enjoy with friends and family,” said Hamza Rao, a resident of Lahore. “Even those who are not into sports, like me, took vicarious pleasure.”
Mr. Rao said he phoned his sister and rushed to her house to celebrate the win. “We ordered cheat meals,” he said, “without any guilt.”
The celebrations, however, cost some fans dearly. The police in the Indian-controlled part of Kashmir, the picturesque Himalayan region that is claimed by both India and Pakistan, said students who celebrated Pakistan’s victory were being investigated under an antiterrorism law.
As Indian players played down the disappointment as something that happens in sport and images of the Indian captain graciously congratulating a victorious Pakistani team made the rounds as expressions of good sportsmanship, Indian fans took it differently.
Online abuse took a communal tone, with trolls channeling much of their anger at the only Muslim player on the team. Some of the abuse was so vicious that many veterans of Indian cricket had to come to the support of the player, Mohammad Shami.
For a majority of the fans of the Pakistani cricket team, the revelry has continued. Mr. Barlas, the cricket fan who watched the game with his college friends, had said a special prayer before the game. Afterward, he gave out sweets in the neighborhood.
On Tuesday he said, “My friends and I are still intoxicated by the win.”
Mujib Mashal contributed reporting.