The failed attack occurred on Tuesday morning about 137km from Somalia's coast and lasted only a few minutes, said First Sergeant Massimo Maccheroni, a spokesman for Italy's central port authority in Rome.
None of the crew was harmed.
Maccheroni said pirates on two small vessels fired at the ship and tried to board the 24,000-tonne Cielo di Milano, but the crew reacted swiftly, increasing speed and activating the ship's anti-fire system, which sends strong jets of water gushing out from the sides of the tanker.
The Italian tanker was coming from the Red Sea and continued on its way to Mombasa, Kenya, Maccheroni said.
Piracy along Somalia's coast is common.
Several ships are reportedly attacked every month, their valuables allegedly stolen and the crews sometimes held for ransom.
On Thursday, pirates in the same waters attacked the Italian cargo ship Jolly Marrone, which also got away.
Last month, Somali pirates hijacked a ship charted by the UN World Food Programme as it carried aid to tsunami victims in Somalia.
The vessel and its crew are still being held.