The sailors were released in Harardhere, a coastal town north of Mogadishu, and were flown to the capital.
"The seven Indian sailors, among them a captain, were held hostage by pirates near Harardhere during the past four years," area governor Hussein Ali Weheliye Irfo said.
"They have suffered hardships both mentally and physically but they are finally free, thanks to the Somali government and other external actors," he added.
Abdulahi Mohamud, and elder and resident of Harardhere, told AFP that a ransom was paid to free the hostages, but said he did know the amount paid.
More From This Section
Officials did not specify where or precisely when the sailors were taken hostage, and did not name the boat they were on.
According to security sources, at least 30 foreign nationals, most of them fishermen, are still being held by Somali pirates.
Those left behind come largely from nations without the capabilities to send in troops to rescue impoverished fishermen, or without the desire or means to pay ransoms.