Pirates in two skiffs fired at the Hong Kong-flagged BW Lion about 1,000 miles (1,600 kilometers) east of the Somali coast, the European Union Naval Force said.
The tanker's captain increased speed and took evasive maneuvers, avoiding the attack, the force said. No casualties were reported. The naval force sent a plane from the Seychelles islands to investigate.
Pirates have launched increasingly bold attacks against vessels in the Indian Ocean and Gulf of Aden in hopes of capturing a ship and crew and collecting ransom. They currently hold more than 190 hostages, including a British couple seized from their personal yacht late last month.
The high-seas hijackings have increased after the recent end of the monsoon season despite an international armada of warships deployed by the United States, the European Union, NATO, Japan, South Korea and China to patrol the region. U.S. drones launched from nearby Seychelles are also patrolling for pirates.
Cmdr. John Harbour, a spokesman for the EU's anti-piracy force, said it wasn't immediately known whether the two skiffs Monday had launched attacks from a larger mothership. He said the work by international navies had pushed pirates out to sea.
"The international transit corridor near the coast is becoming safer, but the pirates are taking fairly drastic action, carrying out attacks so far off the coast," Harbour said. "Certainly our success to date has pushed the pirates out from their normal hunting grounds."
Spain on Monday raised the possibility of sending two captured Somali pirates back home after trying them in Madrid - as a way to win the release of a Spanish trawler held by fellow brigands off the Horn of Africa.
Pirates seized the ship Alakrana and its 36-member crew in the Indian Ocean Oct. 2, and besides a ransom they are demanding the release of two colleagues who were caught the next day by Spanish naval forces. Among the 36 hostages are 16 Spaniards, eight Indonesians, and 12 crew from five African countries.
Justice Minister Francisco Caamano told reporters that Spain would have to try the two in Madrid on kidnapping and other charges "and then see if there is some kind of international agreement" allowing them to serve their sentence in Somalia.
Judge Baltasar Garzon, who ordered the two pirates brought to Madrid, said: "I think there are legal avenues to resolve this conflict. I sincerely think it can be done."
Garzon declined to go into detail. Such a decision would not be up to him, but rather his superiors at the National Court. He insisted, however, that Spain cannot yield to the hijackers and simply free the two men held in Madrid.
Prime Minister Jose Luis Rodriguez Zapatero, speaking during a visit to Poland, declined to confirm or deny that Spain is considering trying the two and then sending them home to serve their sentence.
Zapatero said the situation is too delicate for him to comment on in detail, saying anything he says publicly will eventually reach the hijackers. But he did say, "the situation may be on the right track."
At a meeting Sunday in Nairobi between Spain's ambassador to Kenya and Somalia's prime minister, Spain committed to initiating legal procedures to transfer the two pirates to Somalia, according to a statement from the Somali government.
Prime Minister Omar Abdurashid Sharmarke "is convinced that this course of action will lead to a quick resolution of this issue," the statement said. None of the Spanish officials who spoke Monday went so far as to say Spain had made such a pledge.
The Alakrana's skipper, Ricardo Blach, said in comments carried Monday in the newspaper El Pais that conditions on the ship after 40 days of captivity are hellish.
Blach said the heavily armed pirates number around 30 and are constantly high on qat, a mild stimulant plant, and open fire in the air to scare the sailors and keep them from sleeping.
"They spit in our faces. They kick us," Blach told the newspaper.
The pirates took three sailors ashore Thursday to increase pressure for a settlement, but the Spanish Foreign Ministry insisted Monday they have been taken back aboard the Alakrana, despite reports from the region that they were still ashore.
Meanwhile, the EU Naval Force said that seven pirates its forces arrested after an attack late last month on a French fishing vessel had been transferred to Kenyan authority for prosecution "in accordance with the agreement between the EU and Kenya."
Associated Press reporter Daniel Woolls in Madrid contributed to this report.