The visit, requested by Modi just hours earlier before he flew back home from Afghanistan, raised hopes that stop-and-start negotiations between the nuclear-armed neighbors might finally make progress after three wars and more than 65 years of hostility.
Sharif hugged Modi after he landed at the airport in the eastern city of Lahore and the two left by helicopter for Sharif's nearby family estate.
"So, you have finally come," Sharif told Modi, according to a Pakistani foreign ministry official who was at the meeting.
"Yes, absolutely. I am here," Modi replied, according to the official.
Modi phoned Sharif earlier in the day to wish him on his birthday and asked if he could make a stop in Pakistan on his way home, Pakistan's top diplomat, Foreign Secretary Aizaz Chaudhry, told reporters.
"And the PM said to him, 'Please come, you are our guest, please come and have tea with me'," he said.
It was Sharif's 66th birthday and the family home was festooned with lights for his grand-daughter's wedding on Saturday. Modi and Sharif talked for about 90 minutes and shared an early evening meal before the Indian leader flew back home.
"Among the decisions taken was that ties between the two countries would be strengthened and also people-to-people contact would be strengthened so that the atmosphere can be created in which the peace process can move forward," Chaudhry said.
The next step will be for the two countries' foreign secretaries to meet in the middle of next month, he added.
Modi was on his way back from a visit to Russia. He stopped off in the Afghan capital Kabul earlier on Friday, where he inaugurated a new parliament complex built with Indian help.
The Lahore visit comes after India and Pakistan resumed high-level contacts with a brief conversation between Sharif and Modi at climate change talks in Paris late last month, part of efforts to restart a peace dialogue plagued by militant attacks and long-standing distrust.
A spokesman at Sharif's office earlier told Reuters the two leaders were to discuss a range of bilateral issues, including the disputed Himalayan region of Kashmir, the most contentious issue dividing the nuclear-armed rivals.
A close aide to Modi said the visit was a spontaneous decision by the prime minister and National Security Adviser Ajit Doval, and that it should not be seen as a sudden shift in India's position.
"But yes, it's a clear signal that active engagement can be done at a quick pace," the aide said, declining to be identified.
Mistrust between India and Pakistan runs deep. Modi's visit is the first by an Indian prime minister to Pakistan since the 2008 Mumbai attacks in which 166 people were killed in the Indian city by militants trained in Pakistan.
The two countries were born out of British colonial India in 1947, divided into Hindu-majority India and Islamic Pakistan.
Modi, a Hindu nationalist, came to power in 2014, and has authorized a more robust approach to Pakistan, giving security forces the license to retaliate forcefully along their disputed border and demanding an end to insurgent attacks in Indian territory.
In Afghanistan, many believe that Islamabad sponsors the Taliban insurgency to weaken the Kabul government and limit the influence of India.
Pakistan rejects the accusation but it has struggled to turn around perceptions in Afghanistan, where social media users sent out a stream of glowing commentary on Modi's visit, contrasting the parliament building with the destruction wrought by Taliban suicide bombers.
Nalin Kohli, a spokesman for Modi's Bharatiya Janata Party, said in New Delhi that India was ready to take two steps forward if Pakistan took one to improve ties.
The opposition Congress Party called Modi's visit irresponsible and said that nothing had happened to warrant warming of ties between the rivals. Scheduled high-level talks between the two were canceled in August after ceasefire violations across the border.
"If the decision is not preposterous then it is utterly ridiculous," Congress leader Manish Tewari said.
Opening the parliament building in Kabul, Modi pledged India's support for the Afghan government and urged regional powers, including Pakistan, to work together to foster peace.
"We know that Afghanistan's success will require the cooperation and support of each of its neighbors," he said. "And all of us in the region - India, Pakistan, Iran and others – must unite in trust and cooperation behind the common purpose and in recognition of our common destiny."
As well as the parliament building, India is also supplying three Russian-made Mi-35 helicopters to Afghanistan's small air force, adding badly needed capacity to provide close air support to its hard-pressed security forces.