In May, Iranian lawmakers burned an American flag on the floor of parliament while chanting, “Death to America.” Just last week, President Donald Trump referred to Iran’s government as a “brutal regime” whose “leaders sow chaos, death, and disruption.”

The two countries have been at each other’s throats — and at times on the brink of war — basically ever since Iranian student revolutionaries held 52 Americans hostage for 444 days during the 1979 Iranian Revolution.

So you might be surprised to learn that the US has had a friendship treaty with Iran since 1955.

But now the Trump administration has announced that it is officially ending that treaty.

Speaking to reporters Wednesday, Secretary of State Mike Pompeo said the US would be terminating the treaty, formally known as the 1955 US-Iranian Treaty of Amity, Economic Relations, and Consular Rights. “This is a decision that is, frankly, 39 years overdue,” Pompeo said.

If you’re confused about what’s going on here, don’t worry — you’re not alone. But we’ve got you covered. Here’s what you need to know about the treaty and why the Trump administration is ending it.

The 1955 Treaty of Amity with Iran, very briefly explained

The US has signed these so-called “amity” treaties before, including with Thailand. They’re often agreements to encourage good relationships and trade, a sort of international friendship bracelet.

The US, under the leadership of President Dwight D. Eisenhower, signed one with Iran in 1955. But Iran’s government in 1955 was very different from the government Iran has now. Back then, Iran was ruled by a single leader, called the Shah — a man named Mohammad Reza Pahlavi.

The US and the Shah’s government were really close — in large part because the US had, just two years before, literally orchestrated a coup to overthrow Iran’s democratically elected leader and install the Shah instead.

So the fact that the US signed a friendship treaty with Iran back in 1955 isn’t strange, because the two countries were super close.

What is strange, though, is that the friendship treaty has remained in force to this day, despite the fact that the US hasn’t even had formal diplomatic ties with Iran since 1980, as a result of the hostage crisis — and the fact that the two countries have basically been mortal enemies ever since.

But the treaty has been useful to both countries over the years, as it provides a mechanism for the two sides to confront each other when they have a dispute (instead of, you know, going to war). That mechanism is the International Court of Justice — the top court of the United Nations, based in the Hague in the Netherlands.

Both the US and Iran have used the 1955 Amity Treaty to challenge one another at the ICJ. For instance, the US initiated proceedings against Iran at the ICJ in November 1979 over the hostage crisis, accusing Iran of having violated the treaty.

A few years later, Iran took the US to court at the ICJ after a US warship shot down an Iranian civilian airliner in 1988, killing all 290 passengers. And in 1992, Iran initiated proceedings against the US at the ICJ after the US launched strikes against several Iranian oil platforms in the Persian Gulf.

So while the US and Iran certainly aren’t friends by any stretch of the imagination, their friendship treaty has provided a really useful way for the two sides to settle their problems without resorting to full-on war.

But if the two sides didn’t end the treaty even over major clashes like Iranians taking Americans hostage or the US shooting down an Iranian airliner, why is the Trump administration suddenly ending the treaty now, when nothing even remotely as serious as those incidents has occurred?

The answer is that the ICJ just ruled in Iran’s favor against the United States — and the Trump administration doesn’t want to comply with the ruling, so it’s just quitting the treaty altogether.

How the ICJ decision led to the end of a decades-old pact

The United States reimposed some sanctions on Iran in May, after President Donald Trump pulled the US out of the Iran nuclear deal. Iran challenged those sanctions at the ICJ by claiming that the US had violated this 1955 Treaty of Amity. Iran demanded that all the sanctions immediately be lifted and that the US provide financial compensation to Iran for the losses incurred while the sanctions were in place.

On Wednesday, the ICJ issued its ruling: It rejected Iran’s demands to have the US remove all sanctions and pay it back for the economic losses, but it did order the US to lift some sanctions, on items such as food, medicine, and parts for civilian aviation, on humanitarian grounds.

But instead of just ignoring the ruling (as both countries have done before), the Trump administration decided to tear up the more than half-century-old treaty once and for all.

Announcing the decision, Pompeo accused Iran of “attempting to interfere with the sovereign rights of the United States to take lawful actions necessary to protect our national security” and for “abusing the ICJ for political and propaganda purposes.”

“In light of how Iran has hypocritically and groundlessly abused the ICJ as a forum for attacking the United States, I am therefore announcing today that the United States is terminating the Treaty of Amity with Iran,” Pompeo added.

He did not go into detail about the practical implications of tearing up the bilateral agreement, but he said the ICJ’s decision was a “useful point for us to demonstrate the absolute absurdity” of the treaty between Iran and the United States.

The idea of a friendship treaty between two enemies may be absurd, but in practice, the treaty did serve an important function, by providing a way for the US and Iran to fight each other in the courts instead of on the battlefield.

Now, that’s gone. Scott R. Anderson, a fellow at Brookings and a former US diplomat, noted on Twitter that, according to the terms of the treaty, termination won’t actually go into effect for a year.

But once that year is up, one of the key ways the two longtime enemies have dealt with their grievances against each other will disappear.

Robert Malley, the former White House coordinator for the Middle East, North Africa, and the Gulf and the lead White House negotiator of the Iran nuclear agreement, criticized the administration’s decision in a statement. “This bellicosity undermines U.S. interests and, by escalating tensions and forfeiting diplomacy, risks putting us on a path towards conflict in the Middle East.”