Iran has admitted "unintentionally" shooting down a Ukrainian passenger jet, killing all 176 people on board.
An investigation found that "missiles fired due to human error", President Hassan Rouhani said. He described the crash as an "unforgivable mistake".
The military said the jet flew close to a sensitive site belonging to Iran's Revolutionary Guards and was then mistaken for a hostile aircraft.
Iran had previously rejected suggestions that it was to blame.
The downing of Ukraine International Airlines flight PS752 on Wednesday came just hours after Iran carried out missile strikes on two airbases housing US forces in Iraq.
The strikes were a response to the killing of senior Iranian commander Qasem Soleimani in a US drone strike in Baghdad on 3 January.
Iran initially denied reports that one of its missiles had brought down the Ukrainian plane near the capital, Tehran. But pressure quickly mounted after Western intelligence officials said evidence pointed to Iranian involvement.
Image captionThe plane came down shortly after taking off from Tehran
The Ukrainian flight, which was en route to Kyiv, came down near Imam Khomeini Airport shortly after take-off. Victims included dozens of Iranians and Canadians, as well as nationals from Ukraine, the UK, Afghanistan and Germany.
What explanation did Iran give?
On Saturday morning, an Iranian military statement read on state TV announced that it had struck flight PS752 with a missile by mistake.
The plane had flown near a "sensitive military centre" of the Revolutionary Guards, a force set up to defend the country's Islamic system.
Because of heightened tensions with the US, Iran's military "was at its highest level of readiness", the statement said. "In such a condition, because of human error and in an unintentional way, the flight was hit," it added.
Image copyrightGETTY IMAGES
Image captionIran had previously denied it was a missile strike that downed the Ukrainian jet
The military apologised for downing the plane, saying it would upgrade its systems to prevent such "mistakes" in the future. It added that those responsible would be held accountable and prosecuted.
President Rouhani expressed his condolences. "[Iran] deeply regrets this disastrous mistake," he said on Twitter.
4:40 AM - Jan 11, 2020
Twitter Ads info and privacy
8,611 people are talking about this
Foreign Minister Javad Zarif apologised to the families of the victims but laid part of the blame on the US. "Human error at a time of crisis caused by US adventurism led to [this] disaster," he said.
And Iran's ambassador to the UK, Hamid Baeidinejad, apologised for sharing "wrong findings" about the crash. He had said Iran was "confident" that a missile had not been launched.
"I conveyed the official findings... that [a] missile could not be fired and hit the Ukrainian plane at that period of time," he said. "I apologise."
An act of de-escalation
This is a major admission at a crucial moment for Iran.
Taking responsibility for such a tragic error is highly unusual, but so is the crisis that now confronts the Islamic Republic.
Iran has decided it has to own this disaster to avoid it triggering another war of words with the West or exacerbating further anger and anguish among its own people, who are reeling from one calamity after another.
Make no mistake, this admission was an act of de-escalation.
The repercussions at home may soon be clear. Iran's foreign minister has already sought to shift blame by saying it was "a crisis caused by US adventurism".
But the big question now is: who took the decision to allow a civilian airliner to take off when Iran's airspace was shot through with such tension?
What has the reaction been?
There were 57 Canadian nationals on board the downed flight and Canada's Prime Minister Justin Trudeau described the crash as "a national tragedy".
In a statement, he demanded "transparency and justice for the families and loved ones of the victims".
Ukrainian President Volodymyr Zelensky called on Iran to punish those responsible. "We expect Iran... to bring the guilty to the courts," he said.
Elsewhere, the president of Ukraine International Airlines said: "We didn't doubt for a second that our crew and our plane couldn't be the cause for this horrible crash".
"These were our best guys and girls. The best," Yevhenii Dykhne said of the nine crew members who were on board.
What happened before Iran's announcement?
The statement marks a stark departure from the denials of recent days. As recently as Friday, Iran was insistent that the plane had not been shot down.
"The thing that is clear to us and that we can say with certainty is that this plane was not hit by a missile," Iran's Civil Aviation Organisation (CAOI) chief Ali Abedzadeh said.
On Thursday, government spokesman Ali Rabiei accused the US and its allies of "lying and engaging in psychological warfare" by speculating about the cause of the crash.
But as evidence pointing to a missile strike built, calls for a transparent investigation grew louder.
Video obtained by the New York Times appeared to show a missile streaking across the night sky over Tehran and then exploding on contact with a plane. About 10 seconds later a loud explosion is heard on the ground. The plane, ablaze, continues to fly.
Media captionMobile phone footage appears to show the plane in the moments before it came down
On Thursday, TV images showed a mechanical digger helping to clear debris from the crash site, raising concerns that important evidence could have been removed.
In response, Iran promised a full investigation, inviting air accident agencies from Ukraine, Canada and the US to take part.
On Friday, Canada's Foreign Minister Francois-Philippe Champagne warned Iran that "the world is watching", saying that the families of those on board "want the truth".