Warships from the Iranian navy's 14th fleet reportedly forced the pirates to retreat and the tanker resumed its journey.
Despite numerous patrols by the European Union, other countries and Nato, Somali pirates have seized dozens of ships in the past few years, demanding tens of millions of dollars in ransoms.
Iranian boats have thwarted seven piracy attacks since the end of March and the Iranian navy has been conducting anti-piracy patrols in the Gulf of Aden, between Yemen and Somalia, for almost three years.
Targeted vessels include merchant containers and oil tankers owned or leased by Iran and other countries.
Last month, a UAE bulk carrier owned by a subsidiary of the Abu Dhabi National Oil Company (Adnoc) was the first government-owned ship to be hijacked in the Arabian Sea, east of Oman, while travelling from Australia to Jebel Ali Port in Dubai.
It was boarded by UAE Special Forces who rescued the crew and arrested the pirates.