U.S. officials said they knew by Tuesday afternoon that Iran intended to strike at American targets in Iraq, although it was not immediately clear exactly which they would choose.

The early warning came from intelligence sources as well as communications from Iraq that conveyed Iran’s intentions to launch the strike, officials said.

“We knew, and the Iraqis told us, that this was coming many hours in advance,” said a senior administration official, who like others spoke on the condition of anonymity to discuss sensitive intelligence and diplomatic communications.

“We had intelligence reports several hours in advance that the Iranians were seeking to strike the bases,” the official said.

That gave military commanders time to get U.S. troops into safe, fortified positions at the bases.