The American killing of Maj. Gen. Qassim Suleimani, a hero at home but a terrorist to the United States government, has scaled into one of the most dangerous confrontations between the two countries in the four decades of animosity that have followed the Islamic Revolution.

Iran’s firing of ballistic missiles from inside its borders — not relying on rockets from Iranian-backed proxies — at two of the main military bases where many of the more than 5,000 American troops in Iraq are stationed was a significant escalation of force that threatened to ignite a widening conflict throughout the Middle East.

It was also a stark message from Tehran that it has the will and the ability to strike at American targets in neighboring Iraq.

“It is clear that these missiles were launched from Iran and targeted at least two Iraqi military bases hosting U.S. military and coalition personnel at Al Asad and Erbil,” Jonathan Hoffman, the Pentagon’s chief spokesman, said in a statement.

Iranian news media reported the attacks hours after the remains of General Suleimani were returned to his hometown in Iran for burial amid a huge outpouring of grief and rage at the United States. The funeral procession was so huge and unwieldy that more than 50 people died in a stampede, state news media reported, forcing a delay in the burial.

Iranian officials said the attacks began at 1:20 a.m. — the time General Suleimani was killed Friday by an American drone at the Baghdad International Airport.