Iran has executed a nuclear scientist who gave the US intelligence about the country's contested nuclear weapons.

Shahram Amiri was convicted of spying charges as he "provided the enemy with vital information of the country," said Gholamhosein Mohseni Ejehi, a spokesman for the Iranian judiciary.

Mr Amiri had access to classified information "and he was linked to our hostile and number one enemy, or the Great Satan," said Mr Ejehi, referring to the US.

Mr Ejehi did not explain why authorities never announced Mr Amiri's conviction or his failed appeals court bid, but he said the scientist had access to lawyers.

The scientist was hanged the same week as Tehran executed a group of militants, a year after his country agreed to a landmark accord to limit uranium enrichment in exchange for the lifting of economic sanctions.

US officials in 2010 said they paid Mr Amiri five million dollars to offer the CIA information about Iran's nuclear program, though he left the country without the money.

He defected to the US in 2009 and returned to the Islamic Republic under mysterious circumstances a year later, said authorities who acknowledged for the first time that they secretly detained, tried and convicted a man they once heralded as a hero.

Mr Amiri vanished in 2009 while on a religious pilgrimage to Muslim holy sites in Saudi Arabia, reappearing a year later in a series of online videos filmed in the US.

He then walked into the Iranian interests section at the Pakistani Embassy in Washington and demanded to be sent home.

In interviews, Mr Amiri described being kidnapped and held against his will by Saudi and American spies.

US officials said he was to receive millions of dollars for his help in understanding Iran's contested nuclear program.

Mr Ejehi said: "He neither repented nor compensated and he was trying to leak some information from inside prison, too."

News about Mr Amiri, born in 1977, has been scant since his return to Iran.

Last year, his father Asgar Amiri told the BBC's Farsi-language service that his son had been held at a secret site since coming home.

On Tuesday, Iran announced it had executed a number of criminals, describing them mainly as militants from the country's Kurdish minority.

Then, an obituary notice circulated Mr Amiri's home town of Kermanshah, a city some 500 kilometres (310 miles) south-west of Tehran, according to the Iranian pro-reform daily newspaper Shargh.

It announced a memorial service on Thursday for Mr Amiri, calling him a "bright moon" and "invaluable gem."

Manoto, a private satellite television channel based in London believed to be run by those who back Iran's ousted shah, first reported on Saturday that Mr Amiri had been executed.

BBC Farsi also quoted Mr Amiri's mother saying her son's neck bore ligature marks suggesting he had been hanged by the state.

US officials said Mr Amiri, who ran a radiation detection program in Iran, travelled to the US and stayed there for months under his own free will.

Analysts abroad suggested Iranian authorities may have threatened Mr Amiri's family back in Iran, forcing him to return.

But when he returned to Iran and was welcomed by government officials, Mr Amiri said Saudi and American officials kidnapped him while he visited the Saudi holy city of Medina.

He also said Israeli agents were present at his interrogations and that CIA officers offered him 50 million dollars to remain in America.

"I was under the harshest mental and physical torture," he said.

Mr Amiri's case indirectly found its way back into the spotlight in the US last year with the release of emails sent by US Democratic presidential candidate Hillary Clinton while she served as secretary of state.

The release of those emails came amid criticism of Mrs Clinton's use of a private account and server that has persisted into her campaign against Republican candidate Donald Trump.

An email forwarded to her by senior adviser Jake Sullivan on July 5 2010 - just nine days before Mr Amiri returned to Tehran - appears to refer to the scientist.

"We have a diplomatic, 'psychological' issue, not a legal one. Our friend has to be given a way out," the email by Richard Morningstar, read a former State Department special envoy for Eurasian energy.

"We should recognize his concerns and frame it in terms of a misunderstanding with no malevolent intent and that we will make sure there is no recurrence.

"Our person won't be able to do anything anyway. If he has to leave so be it."

Another email, sent by Mr Sullivan on July 12 2010, appears to obliquely refer to the scientist just hours before his story became widely known.

"The gentleman ... has apparently gone to his country's interests section because he is unhappy with how much time it has taken to facilitate his departure," wrote Mr Sullivan.