India and Pakistan exchanged prisoners through the Attari-Wagah border on Thursday.
While India freed three prisoners, Pakistan repatriated 19 Indians, including 13 fishermen.
Mohammed Ahmed, a resident of Moradabad in Uttar Pradesh who was arrested for espionage, was released after 20 years.
He had gone to Pakistan to visit his aunt with a valid passport and visa. The police arrested him when his visa validity expired during his stay there.
Hari Chand of Maharashtra, who spent six years in Pakistan, was arrested when he was spotted with an expired visa.
Ramraj of Jammu and Kashmir has spent nine years behind bars.
India freed three prisoners who had crossed over to its territory inadvertently.