Mr. Modi soon arrived at Mr. Sharif’s private residence outside Lahore, meeting the Pakistani leader’s family at an estate decked out with decorations for the wedding of Mr. Sharif’s granddaughter. The two leaders met for almost an hour, aides said, speaking pleasantly and pledging to restart talks between the two nations.

Among the factors that may have prompted Mr. Modi to reach out is that Pakistan has a new national security adviser, said Ashok Malik, a New Delhi-based political analyst. The Indian leader, Mr. Malik said, may also have seen an opportunity for “a positive headline.”

“He realizes he needs to be seen as engaging, and he is under pressure from the West and the Saudis to engage,” Mr. Malik said. “What came across in the past year was this very combative guy, snarling at his opponents. This has allowed him to appear serious and statesmanlike.”

In an interview last week, T.C.A. Raghavan, the departing Indian high commissioner in Islamabad, the Pakistani capital, said that relations between the two countries were at “a tipping point.”

For his part, Mr. Sharif has been an advocate of better ties with India, and he has been eager to enhance trade ties with it. But his desires have been viewed with suspicion and disapproval by the powerful Pakistani military establishment, which remains focused on the resolution of the longtime dispute over Kashmir and accuses India of fostering separatists in Pakistan’s Baluchistan Province.