Surjeet Singh, 69, was greeted at the Wagah border crossing by his son and other family members and well-wishers.
Wearing marigold garlands around his neck, Mr Singh admitted to reporters: “I had gone there for spying.”
There was confusion this week when Pakistan said another Indian, Sarabjit Singh, would be freed, but later clarified it was to be Surjeet Singh.
Sarabjit Singh has been on death row for more than 21 years after being convicted of spying and bomb attacks he denies carrying out.
Campaigners are still pressing for him to be freed too as part of what is being seen as a recent thaw in diplomatic relations between India and Pakistan.
‘Really happy’
TV pictures showed Mr Singh crossing the Wagah border, accompanied by Border Security Force personnel and police.
Family members greeted him by putting several marigold garlands around his neck and offered him sweets.
“I am free after 30 years. I’ve met my family, I’m really happy,” he told reporters.
Mr Singh said he had been treated well in jail.
He said he met his fellow prisoner, Sarabjit Singh, regularly in Lahore’s Kot Lakhpat prison and that he had been well treated too.
Surjeet Singh said he would do everything possible to get his fellow prisoner freed. He said “media hype” had spoiled Sarabjit Singh’s case.
Surjeet Singh now plans to go to the Golden Temple, Sikhdom’s holiest place, “to pray and hug my children”.
Earlier this week, Pakistan’s law minister conveyed to the government that Surjeet Singh had completed his life term and ought to be released and sent back to India.
That followed reports, which turned out to be wrong, that Pakistan was about to free Sarabjit Singh.
Pakistan and India frequently arrest each other’s citizens, often accusing them of being spies after they have strayed across the land or maritime border.
In recent years, several Indians returning from Pakistani jails have admitted to spying.