Overall, the hackers attempted to access 241 accounts — four successfully — though none of those penetrated was associated with presidential campaigns or current or past US officials, Microsoft said.
The announcement is the latest sign that foreign governments are looking for ways to potentially disrupt the 2020 presidential election. US intelligence officials have sounded the alarm about the risks for months.
Russia’s hacking of the Democratic National Committee and Hillary Clinton’s campaign, as well as the subsequent leaks of emails during the 2016 election hurt Mrs Clinton’s electoral hopes and was a focal point in special counsel Robert Mueller’s probe.
Foreign hackers have long targeted US government and politicians, generally with little notice.
But the disruption caused by Russia’s attack has heightened awareness and prompted fears that other nations will try to follow Russia’s example.
Iran in particular could have a stake in the outcome of the US election after President Donald Trump withdrew the United States from a nuclear agreement and stepped up sanctions against the country.
The US Department of Homeland Security said it was working with Microsoft to “assess and mitigate impacts”.
Chris Krebs, director of the department’s Cybersecurity and Infrastructure Security Agency, said much of the activity is likely “run-of-the-mill” foreign intelligence service work.
But “Microsoft’s claims that a presidential campaign was targeted is yet more evidence that our adversaries are looking to undermine our democratic institutions”, Mr Krebs said.
In a blogpost released on Friday, Microsoft’s Tom Burt, corporate vice president for customer security and trust, said that owners of four accounts that were compromised by the hackers have been notified.
The attacks by a group Microsoft calls Phosphorous occurred during a 30-day period between August and September.
Mr Burt said the Iranian hackers used password reset and account recovery features to try to take over accounts. For example, they gathered phone numbers belonging to targets to help with a password reset.
In other cases, they tried to get into secondary email accounts that might be linked to the Microsoft account to gain access via a verification email.
The hackers researched their targets, making more than 2,700 attempts to identify emails belonging to a specific Microsoft customer.
The company has previously taken legal steps to combat Iran-linked hackers, suing them in federal court in Washington DC, so Microsoft could take control of websites Phosphorous used to conduct hacking operations and to stop attacks.
In July, Microsoft announced that it had detected more than 740 infiltration attempts by nation-state actors in the past year targeting US-based political parties, campaigns and other democracy-focused organisations including think tanks and other nonprofits.