In April 2008, a senior British intelligence official flew to Tel Aviv to deliver an explosive revelation to his Israeli counterparts: Britain had a mole in Iran with high-level access to the country’s nuclear and defense secrets.

The spy had provided valuable information — and would continue to do so for years — intelligence that would prove critical in eliminating any doubt in Western capitals that Iran was pursuing nuclear weapons and in persuading the world to impose sweeping sanctions against Tehran, according to intelligence officials.

The identity of that spy has long been secret. But on Jan. 11, the execution in Iran of a former deputy defense minister named Alireza Akbari on espionage charges brought to light something that had been hidden for 15 years: Mr. Akbari was the British mole.

Mr. Akbari had long lived a double life. To the public, he was a religious zealot and political hawk, a senior military commander of the Revolutionary Guards and a deputy defense minister who later moved to London and went into the private sector but never lost the trust of Iran’s leaders. But in 2004, according to the officials, he began sharing Iran’s nuclear secrets with British intelligence.

He appeared to get away with it until 2019, when Iran discovered with the assistance of Russian intelligence officials that he had revealed the existence of a clandestine Iranian nuclear weapons program deep in the mountains near Tehran, according to two Iranian sources with links to Iran’s Revolutionary Guards.

In addition to accusing Mr. Akbari of revealing its nuclear and military secrets, Iran has also said he disclosed the identity and activities of over 100 officials, most significantly Mohsen Fakhrizadeh, the chief nuclear scientist whom Israel assassinated in 2020.

Britain has never publicly acknowledged that Mr. Akbari, who became a British citizen in 2012, was its spy. “It is our longstanding policy not to comment on matters relating to intelligence,” said William Archer, the spokesman on Iran for the British Foreign Office.

The New York Times reported in September 2019 that the source of the intelligence on the nuclear site, called Fordo, was a British spy. The intelligence on Fordo that Mr. Akbari provided was one of the revelations that the British intelligence official passed on to Israeli counterparts and other friendly agencies in 2008, according to three Western intelligence and national security officials.

The State Department and the National Security Council said they could not comment on questions about Mr. Akbari.

The following account of Mr. Akbari’s activities is based on interviews with American, British, Israeli, German and Iranian current and former intelligence and national security officials and senior diplomats. Some requested anonymity because they were not authorized to speak on the record.

Mr. Akbari, who was 62 when he was executed, was an unlikely spy. He displayed a fanatical allegiance to the ideals of the Islamic Republic and unwavering support for its leaders, according to interviews with his brother Mehdi Akbari and people who knew him.

His most distinct physical feature was a dent on his forehead — a sign of his devotion to the Shia faith of Islam that came from pressing his forehead to the mohr, a clay stone used in daily prayers. He held extremist political views, expressed in fiery writings, speeches and interviews and, according to a senior Iranian diplomat and an adviser to the government, in official meetings, he argued that Iran should acquire a nuclear weapon.

“My brother was deeply religious and very revolutionary, more so than anyone in our family,” said Mehdi Akbari.

Mr. Akbari, who was born into a conservative middle-class family in the city of Shiraz, was a teenager when the Iranian revolution in 1979 toppled the monarchy and war with Iraq followed, his brother said. Inflamed with revolutionary passion, he and an older brother enlisted as soldiers, and by the time he left the front lines almost six years later, he was a decorated commander of the Revolutionary Guards.

Returning to civilian life, Mr. Akbari ascended the ranks, rising to deputy defense minister and holding advisory positions on the Supreme National Security Council and other government bodies. He forged close relationships with two powerful men: Mr. Fakhrizadeh, the nuclear scientist, and Ali Shamkhani, the head of the council, whom he served as a deputy and an adviser.

“He was extremely ambitious, an excellent analyst with superior writing and speaking skills and people trusted him,” said Foad Izadi, a policy analyst in Iran who is close to the government and the Revolutionary Guards. “He had access to a lot of sensitive, secretive information on nuclear and military programs.”

In 2004, amid growing suspicions in Israel and the West that Iran was secretly pursuing a nuclear weapons program, Mr. Akbari was responsible for convincing key embassies in Tehran that it was not, meeting regularly with the ambassadors of Britain, China, France, Germany and Russia.

In eight short videos aired by state television after his execution, Mr. Akbari, dressed in suits, clean shaven and sitting in an office, detailed his spying activities and his recruitment by Britain at a function at the British Embassy in Tehran. But later, in an audio message broadcast by BBC Persian — it had been obtained through his family, according to Mr. Akbari’s brother — Mr. Akbari said the confessions were coerced.

The motivation for Mr. Akbari’s actions remain unclear. He said in the video that he was driven by “greed and power,” though also denied having financial problems. Iran says Mr. Akbari betrayed the country and traded state secrets for money. His family denies he was a spy and says that many assertions in the videos were fabricated by the Iranian government. But, they say, many of the dates and events in the videos were correct.

In the videos, Mr. Akbari said he was recruited in 2004 and told he and his family would be given visas for Britain. The next year, he traveled to Britain and met with an MI6 handler, he said. Over the next few years, Mr. Akbari said he created front companies in Austria, Spain and Britain to provide cover for meetings with his handlers. Iran has said that MI6 paid Mr. Akbari nearly 2 million pounds, currently about $2.4 million.

Mr. Akbari met with the British ambassador in Tehran as part of his official job, and traveled to Europe often for business, Mehdi Akbari said. He said that his brother, like many Iranian officials, had started branching out into various businesses while he was employed by the government, and that he was financially secure.

Mehdi Akbari described a scene in which the brothers sat in a Tehran garden one summer afternoon in 2006 chatting about work. When he suggested that they start an oil and gas consultancy business, his brother declined, showed him a business card that said he was a board member of an energy company in Austria and said he “was extremely tied up” with this new venture.

Mr. Akbari retired from his official posts in 2008, his brother said, but continued to serve as an adviser to Mr. Shamkhani and other senior officials.

Later that year, Mr. Akbari was arrested and held for four months on accusations that he was spying for Britain, according to his brother and two family friends. The interrogations did not yield a confession, and many of Mr. Akbari’s powerful friends vouched for him, they said. He was released on bail, his brother said. The case was closed and he was allowed to travel freely.

In April 2008, Britain received and shared with Israel and Western agencies the intelligence about Fordo, a uranium enrichment facility deep inside an underground military complex, that was part of Iran’s efforts to build a nuclear bomb. Fordo’s discovery changed the world’s understanding of Iran’s nuclear program and redrew the West’s military and cyber plans for countering it.

“The information about Fordo shocked us,” Yoni Koren, who was the chief of staff for Israel’s defense minister at the time, said in an interview in 2019. (Mr. Koren died in January.)

“The great contribution of the British to the combined Western efforts to gather data from inside the Iranian nuclear project was always in human intelligence,” he said. “They had a foot on the ground in places where neither we nor the Americans had a presence.”

The intelligence Britain shared with Israel in 2008 was soon passed on to Western intelligence agencies, according to a person who held a senior position in German intelligence at the time. In September 2009, at a Group of 7 summit in Pittsburgh, President Barack Obama, along with the leaders of Britain and France, revealed that Fordo was a nuclear enrichment plant.

Western intelligence agencies had long been aware through satellite imagery that Iran was building a facility deep inside the mountains at Fordo. But they had thought the site was a military storage facility and were unaware of its transformation into a secret nuclear enrichment site.

“The discovery of Fordo radically altered the attitude of the international community toward Iran,” said Norman Roule, the former national intelligence manager for Iran at the C.I.A. He added that it helped convince China and Russia that Iran had not been transparent about its nuclear program and drove the push for more sanctions.

Even after his brief arrest and retirement from official jobs, Foreign Ministry officials continued to seek advice from Mr. Akbari, and informed him about closed-door meetings about policies and nuclear negotiations, according to a senior Iranian diplomat.

Mr. Akbari also was traveling regularly to London. In 2010, he had a heart attack there, his brother said, and stayed. He was soon joined by his wife and two daughters, and eventually obtained British citizenship, living off an investment portfolio and traveling to Iran to maintain contacts with senior officials. In the videos, Mr. Akbari said he faked the heart attack in order to stay in Britain.

Still, he traveled back and forth from London to Tehran at least three times from 2010 to 2019 and stayed at a family home he had kept in Tehran, his brother said.

In 2019, Mr. Akbari flew to Iran for a final time after Mr. Shamkhani, the Supreme National Security Council head, told him the country needed him on an urgent nuclear and defense matter, his brother said.

A few days after his return to Tehran, he was summoned to the Intelligence Ministry. Worried, he called Mr. Shamkhani, who told him that the authorities had heard he was in contact with MI6 and urged him to cooperate to prove his innocence, his brother said. After several interrogations, he was arrested.

At some point, Iran discovered that Mr. Akbari was the source of the Fordo leak, according to the two Iranians with connections to the Revolutionary Guards, information that was confirmed by Russian intelligence. It is unclear how Russia, a close ally of Iran, discovered the information.

In 2020, a year after Mr. Akbari’s arrest, Israel assassinated Mr. Fakhrizadeh, the nuclear scientist, with a remote-controlled robot as he was driving to his weekend home in a mountain village near Tehran.

Mr. Akbari was detained by the Intelligence Ministry and held in solitary confinement for months in an underground detention and then in Tehran’s notorious Evin prison, his brother said. The family was told to keep the arrest under wraps. Iranian officials said on state media after his execution that they had him regularly log in to a computer provided by the British and communicate with his handlers to mislead them.

In January, a little over three years after Mr. Akbari’s arrest, as Iran was reeling from months of anti-government protests, a crackdown by the authorities and a new round of international sanctions, the Iranian authorities announced that he was a spy.

Execution of senior officials is extremely rare in Iran. The last time a senior technocrat was executed was in 1982. But just days after Mr. Akbari’s arrest became public, prison guards escorted him at sunrise to a walled outdoor space, according to Iranian sources and diplomats. A rope was placed around his neck and, within minutes, his lifeless body was dangling from a gallows.

Mr. Akbari was buried in a vast cemetery in the outskirts of Tehran without his relatives’ knowledge or presence. His family said the authorities only showed them a video of his body being washed and prepared according to Islamic rituals.

“We could have never imagined this, and I don’t understand the politics behind it,” said Mr. Akbari’s wife, Maryam Samadi.

Britain condemned Tehran for executing Mr. Akbari, briefly recalled its ambassador and imposed new sanctions on Iran.

Mr. Akbari’s family was allowed to hold a memorial service in Tehran 40 days after his death. They rented a hall in a mosque, arranged white flower baskets and served trays of halvah, the traditional sweet served at funerals. They sat on chairs that lined the walls, ready to greet a procession of his friends, colleagues and associates from his various roles serving the Islamic Republic for 40 years.

But nobody came, they said. Only his family attended.

Farnaz Fassihi reported from New York, and Ronen Bergman from Tel Aviv. Mark Landler contributed reporting from London.