NICOSIA, Cyprus (AP) _ The visit of Romania's Nicolae Ceausescu, only days before the Communist dictator was overthrown, was needed to protest a defense contract, Iran's foreign minister said today.

Foreign Minister Ali Akbar Velayati was summoned to Parliament to explain why Ceausescu was invited to Iran last month, but refused to give details on the ''vital, defense-related'' contract with Romania.

''Only part of this contract had been implemented, but if we had delayed the trip and stopped Ceausescu from coming, there was the possibility that this contract would not be implemented,'' Velayati was quoted as saying by official Tehran radio, monitored in Nicosia.

''This would be a fundamental disadvantage to the defense of the Islamic Republic.'' During Iran's eight-year war with Iraq, Romania was one of the Eastern European countries that supplied Iran with armaments, including light weapons.

Velayati has been criticized in the official media and by radical leaders who oppose the government of President Hashemi Rafsanjani.

He also told the Parliament that Romania's position as a non-permanent member of the U.N. Security Council was important for Iran, which is trying to persuade the world body to exert pressure on Iraq to withdraw troops from Iranian territory seized in war.

Ceausescu was welcomed in Tehran and signed an agreement to buy 1 million barrels of oil and 1 billion cubic meters of gas a year from Iran.

Velayati said that despite Ceausescu's fall, contracts signed by him were still considered valid by Romania's new government.

Velayati rejected allegations that ''we had not given sufficient information to our authorities, especially to the president, about the situation in Romania.''

Ceausescu was deposed by a popular uprising Dec. 22 and he and his wife, Elena, were executed Dec. 25 after they were found guilty during a secret trial of genocide and other ''grave crimes.''

The uprising against Ceausescu began just before he left for Tehran Dec. 18.

Iran's ambassador to Bucharest, Mohammad Jamshid Gowhari, was dismissed following Ceausescu's overthrow, reportedly for his failure to inform the Foreign Ministry of the extent of the opposition to Ceausescu.

But Velayati said his dismissal was because ''after Ceausescu's trip he had said things in various places that did not befit the status of a diplomat.''

Velayati did not elaborate.