(Adds comments from Petrobras, foreign minister, company source, details of ruling and context, bylines)
By Lisandra Paraguassu and Rodrigo Viga Gaier
BRASILIA/RIO DE JANEIRO, July 25 (Reuters) - Brazil's top court on Thursday ordered state-run oil company Petroleo Brasileiro SA to refuel two Iranian grain vessels stranded on the Brazilian coast due to U.S. sanctions holding up sales of fuel needed for their return trips.
Chief Justice Dias Toffoli overturned a lower court ruling that allowed Petrobras, as the oil major is known, to refrain from fueling the vessels.
Petrobras had denied service, citing the risk of consequences from U.S. sanctions. However, the risk is reduced if it is simply obeying a Supreme Court ruling, said a company source who was not authorized to publicly comment on the matter.
The Petrobras press office has not been officially notified about the court's decision, it said. The company said it will evaluate its options once it learns the details of the decision.
Brazilian Foreign Minister Ernesto Araujo told reporters in Brasilia that the legal process must be followed in the case, but Petrobras faces risks if it violates U.S. sanctions.
In his decision, Toffoli said the bulk carriers Bavand and Termeh are under contract to Brazilian company Eleva Química, which is not covered by U.S. sanctions, and so are entitled to receive the fuel and proceed on their return trips.
Eleva Química did not return a request for comment.
Toffoli said the Petrobras refusal to refuel the ships would cause economic losses for Eleva and Brazil.
Iran is a major buyer of Brazilian commodities and the top destination for its corn exports this year. The country also buys Brazilian soybeans, sugar, meat and other products.
The ships Bavand and Termeh are among five Iranian vessels testing a new trade route, bringing urea to Brazil and returning to Iran with corn. Iran is trying to boost sales of petrochemicals like urea as sanctions hammer its oil industry.
For two other Iranian ships at Brazilian ports, MV Delruba and Ganj, it is not clear if they will need to refuel to get back to Iran after unloading their urea and loading corn.
The fifth vessel, Daryabar, managed to leave Brazil and is currently bypassing South Africa's Cape of Good Hope, according to Refinitiv's Eikon ship tracking system.
All five ships are on the U.S. sanctions list. The sanctions also bar trading of urea, but not food. (Reporting by Lisandra Paraguassu in Brasilia and Rodrigo Viga Gaier in Rio de Janeiro; Additional reporting by Marta Nogueira in Rio de Janeiro, Jake Spring in Brasilia and Marcelo Teixeira in Sao Paulo; Writing by Ana Mano and Marcelo Teixeira Editing by Brad Haynes, Chizu Nomiyama and Richard Chang)