Pakistan Prime Minister Nawaz Sharif, left, and Indian Prime Minister Narendra Modi walk through a guard of honor in Lahore, Pakistan. Mr. Modi made a surprise visit to Pakistan to meet his counterpart weeks after the nuclear-armed rivals decided to restart high-level peace talks. PHOTO: PIB/AGENCE FRANCE-PRESSE/GETTY IMAGES
Pakistan Prime Minister Nawaz Sharif, left, and Indian Prime Minister Narendra Modi walk through a guard of honor in Lahore, Pakistan. Mr. Modi made a surprise visit to Pakistan to meet his counterpart weeks after the nuclear-armed rivals decided to restart high-level peace talks. PHOTO: PIB/AGENCE FRANCE-PRESSE/GETTY IMAGES

ISLAMABAD, Pakistan—India’s prime minister made a surprise stop Friday in Pakistan to meet his counterpart in a richly symbolic gesture likely to add momentum to a tentative reconciliation process between the nuclear-armed neighbors.

Pakistani Prime Minister Nawaz Sharif embraced India’s Narendra Modi at the airport in the eastern city of Lahore. They walked from the plane holding hands and smiling broadly. The visit, the first by an Indian prime minister in more than a decade, coincided with Mr. Sharif’s birthday.

“This was a goodwill visit, in which it was decided that both countries will have to examine each other’s concerns, to understand each other’s issues, and open up ways to peace,” said Aizaz Chaudhry, Pakistan’s foreign secretary.

New Delhi and Islamabad agreed earlier this month to restart a comprehensive dialogue aimed at improving relations. The two countries have fought three wars since independence from the U.K. in 1947. Among the issues are rival claims to the border region of Kashmir.

The trip was heavy with imagery. Mr. Modi has Hindu nationalist roots and has railed against Pakistan. Lahore is Mr. Sharif’s hometown. Not only was Friday Mr. Sharif’s birthday, but his family was also celebrating a wedding. Dec. 25 is also the birthday of the founder of Pakistan, Muhammad Ali Jinnah.

“I’m amazed myself, quite honestly. This is undoubtedly a very fine gesture by the Indian prime minister. It makes it very personal,” said Mahmud Durrani, a retired Pakistani general and former national security adviser. “My hope has risen. We hope something positive develops from this.”

The U.S. also welcomed the visit. “Better relations between neighbors India and Pakistan will benefit the people of the entire region,” said State Department spokesman John Kirby.

According to Mr. Chaudhry, Mr. Modi, who was visiting Kabul, called Mr. Sharif around 11:30 a.m. Friday local time to wish him happy birthday and said that he wanted to stop over on his way back to India, which Mr. Sharif welcomed.

Mr. Modi, who came to power in 2014, arrived around 4:30 p.m. and stayed for a couple of hours at Mr. Sharif’s sprawling estate on the outskirts of Lahore.

“Spent a warm evening with Sharif family at their family home. Nawaz Sahab’s birthday & granddaughter’s marriage made it a double celebration,” said a tweet on Mr. Modi’s official Twitter feed.

The foreign secretaries of the two countries are to meet in January to decide how the peace dialogue will proceed, said Sartaj Aziz, Mr. Sharif’s special adviser on foreign affairs. “All issues are on the table,” Mr. Aziz said.

The visit was so sudden that several Pakistani officials, including Mr. Aziz, didn’t have time to reach Lahore.

The core of the dispute between the neighbors is the mountainous region of Kashmir, which is claimed by both. New Delhi accuses Pakistan of sponsoring jihadist groups that attack India and wants the alleged Pakistani masterminds of the 2008 attack on Mumbai that killed 166 people to face justice.

Islamabad alleges that India supports violent groups in Pakistan, including a separatist movement in its western province of Balochistan.

In the last few weeks, the two countries have begun to mend ties, following tension that erupted into regular exchanges of fire across the border for the last year and a half.

While the main opposition parties in Pakistan welcomed the visit, Mr. Modi faced criticism in India from his parliamentary foes. The opposition Congress party said the visit lacked “seriousness” and any substantive guarantees from Pakistan on major issues like the prosecution of those accused in the Mumbai attacks.

“If cross-border militancy from Pakistan stops, latent goodwill in India will surface,” said Radha Kumar, head of the Delhi Policy Group, an independent Indian think tank. “Peace with Pakistan has been a top priority of successive Indian governments, which has been interrupted by acts of terrorism.”

Mr. Modi invited Mr. Sharif, a long-term proponent of making peace with India, to his swearing-in ceremony in May 2014, but relations since have mostly been tense, leading to fears of Indian military retaliation if it suffered another terrorist attack traced to Pakistan.

Better India-Pakistan ties could improve the prospects for stability in Afghanistan, where analysts say their rivalry is a driver of that country’s long-running war.

Pakistan is alleged to support the Taliban insurgency in Afghanistan as a way of countering Indian influence there, a charge that Islamabad denies. Islamabad charges that India uses Afghanistan to funnel aid to Pakistani rebel groups, an accusation that New Delhi rejects.

Pakistani analysts say that Mr. Modi’s previous failure to reciprocate Mr. Sharif’s outreach had allowed the hawkish Pakistani military to take control of relations with India.

One of India’s leading English-language newspapers, The Hindu, described Mr. Modi’s visit as “a transformational moment” in an editorial published on its website.

“By making the journey from Kabul to Lahore, he has transformed Afghanistan from a battlefield between India and Pakistan into a facilitator of good relations. The road ahead is certainly perilous. Relations with Pakistan have often seen setbacks far worse than the strides in ties,” the newspaper wrote.

In Mr. Sharif’s last term as prime minister, in the late 1990s, the two countries made progress toward peace, again with personal rapport developing between him and the then Indian prime minister, Atal Bihari Vajpayee, also from Mr. Modi’s Bharatiya Janata Party.

But then a border conflict in 1999 precipitated by the Pakistani army seizing an outpost claimed by India, in the Kashmir region, ended the process. Mr. Sharif was ousted soon afterward in a coup, returning to power in 2013.

The subsequent military government led by Gen. Pervez Musharraf got close to a peace deal with India about a decade ago but he was forced out of office in 2008, when democracy was restored.

Mr. Modi’s trip to Kabul was his first. He held discussions with Afghan President Ashraf Ghani and inaugurated the Afghan parliament building in Kabul, which was funded by the Indian government at a cost of $90 million.

“Afghanistan will succeed only when terrorism no longer flows across the border, when nurseries and sanctuaries of terrorism are shut and their patrons are no longer in business,” Mr. Modi said in his speech to Afghan parliamentarians, in an apparent reference to Pakistan. “Terror and violence cannot be the instrument to shape Afghanistan’s future.”

Mr. Modi reiterated India’s support for strengthening Afghanistan’s defensive capabilities, in particular its air force, which relies heavily on U.S. Army planes and helicopters.

“Afghanistan is not hostile to anyone and we want friendship,” Mr. Ghani said. “Our entire nation wants lasting and dignified peace.”

Corrections & Amplifications:
Lahore is in eastern Pakistan, and Mr. Modi called Mr. Sharif Friday at around 0630 GMT and arrived in Pakistan at 1130 GMT. An earlier version of this article incorrectly stated Lahore’s location and the GMT times.