Addressing an online news conference, judiciary spokesman Gholamhossein Esmaili named one of the five as Shahram Shirkhani, saying he had spied for Britain and tried to recruit some Iranian officials for the British MI6 espionage service.
He added that Shirkhani had passed on sensitive information about banking and Defence Ministry contracts, and had been convicted and received a prison sentence.
Masoud Mosaheb, the co-chairman of the Iranian-Austrian Friendship Society, was sentenced to 10 years imprisonment for sharing information on Iran's "missile and nuclear projects" with Israel's Mossad and the German intelligence service, Esmaili said.
The Austrian Foreign Ministry said efforts to achieve the release of Mosaheb, an Iranian-Austrian dual national, continued unabated and at the highest level.
"Since the person detained in Iran is an Austrian-Iranian dual citizen ... Iran does not allow the monitoring of legal proceedings, visits to prison or access to trial and medical records," the ministry said in a statement to Reuters.
Iran does not recognize dual nationally. Austrian media reported that Mosaheb, 72, had been imprisoned in Iran since January 2019.
Esmaili gave no details on the other three detainees, but indicated that they were working in state bodies. "We had the arrests in the foreign, defense and energy ministries as well as in the Atomic Energy Organisation," Esmaili said.
Separately, the Intelligence Ministry said in a statement "a number of spies related to foreign intelligence services were identified and arrested."
"They sought to spy on sensitive and vital centers in the economic, nuclear, infrastructure, military and political areas for the CIA, the Mossad and some European countries," said the statement read on TV.
There was no immediate indication whether these individuals were the same ones referred to by Esmaili.
Several explosions and fires have occurred around Iranian military, nuclear and industrial facilities in the past months, from a blast at the underground Natanz nuclear facility to a blaze at a military and weapons development facility.
Some lawmakers suggested that the explosion in Natanz was caused by a "security breach," Iranian media reported in July.In an article in early July, state news agency IRNA addressed what it called the possibility of sabotage by enemies such as Israel and the United States.