The Enrico Ievoli, owned by Naples-based shipping company Marnavi, was carrying caustic soda from the United Arab Emirates to the Mediterranean and has seven Indians, six Italians and five Ukrainians on board.
"The foreign ministry confirms the release of the crew of the Italian ship 'Enrico Ievoli' off the Somali coast," the ministry said in a statement.
Foreign Minister Giulio Terzi was quoted as expressing his "great satisfaction" and said it was part of "a wider diplomatic effort carried out also with Somali authorities in recent months."
Italian Prime Minister Mario Monti in February asked his Somali counterpart Abdiweli Mohamed Ali to do "everything in his power" to ensure the release.
"This incident is further confirmation of the gravity of the security threat posed by the phenomenon of piracy," Terzi said on Monday.
Ship owner Domenico Ievoli was quoted by ANSA news agency as saying: "The ship has already left Somalia and there are Italian military on board."
An Italian warship met the Ievoli after it came out of Somali waters and sent a party of armed marines aboard to protect it on the remainder of its journey.
The Ievoli, a 138-metre (453-foot) vessel, was carrying 15,750 tons of caustic soda when it was hijacked in the Indian Ocean.
The Italian navy, which is taking part in anti-piracy operations in the region, had already thwarted an attack on the same ship in 2006 near Yemen.
Three other hijacked Italian vessels were freed from Somali pirates in November and December, two of them reportedly following ransom payments, among dozens of ships that have been captured in recent years.
There are no Italian vessels now in Somali captivity but pirates still hold hundreds of hostages and dozens of ships.
The Savina Caylyn, an oil tanker with five Italians and 17 Indians on board, was freed on December 21 after more than 10 months in captivity.
In November, the cargo ship Rosalia D'Amato with a crew of 21 was released after seven months in the hands of Somali pirates.
Also in November, British and US commandos freed another Italian vessel, the Montecristo, with seven Italians, 10 Ukrainians and six Indians on board.
Kalashnikov-wielding pirates prowl far out across the Indian Ocean from their bases in war-torn northern Somalia, seizing foreign ships which they hold for several months demanding multi-million dollar ransoms.