The U.S. military has launched an investigation into the deaths of two elite Army Rangers in Afghanistan early Thursday, saying they may have been killed by friendly fire during a three-hour battle with Islamic State militants.

Sgt. Joshua P. Rodgers, 22, and Sgt. Cameron H. Thomas, 23, died during a large nighttime raid in Nangarhar province, the Pentagon said Friday. They were members of the Army’s 3rd Battalion, 75th Ranger Regiment, a Special Operations force that specializes in raids.

U.S. military headquarters in Kabul said in a statement Friday that the operation began about 10:30 p.m. Wednesday and included two platoons of Rangers and a similar number of Afghan commandos. They came under fire from “multiple directions and well-prepared fighting positions” within minutes of their helicopters landing, the statement said.

U.S. and Afghan forces nonetheless closed on their targets and killed several high-level leaders from Islamic State-Khorasan, the group’s affiliate in Afghanistan, and up to 35 fighters, U.S. military officials said.

Navy Capt. Jeff Davis, a Pentagon spokesman, said Friday that about 50 Rangers and 40 commandos were involved. He declined to say how many militants they faced, but he said U.S. jets, drones, ground-attack helicopters and an AC-130 gunship were used throughout the operation.

“We were expecting a tough fight,” he said.

The U.S. military statement said airstrikes were launched in defense of U.S. forces to enable operations and to evacuate the fallen soldiers and a third Ranger who was wounded about 3 a.m. Thursday. The Pentagon has no indication there were any civilian casualties, the statement said.

Defense Secretary Jim Mattis said in a statement Friday that the families of the two soldiers have his sympathy.

“Fighting alongside their Afghan partners, Josh and Cameron proved themselves willing to go into danger and impose a brutal cost on enemies in their path,” Mattis said. “They carried out their operation against ISIS-K in Afghanistan before making the ultimate sacrifice to defend our nation and our freedoms. Our nation owes them an irredeemable debt, and we give our deepest condolences to their families.”

The raid occurred in the Mohmand Valley, where U.S. forces two weeks ago dropped for the first time in combat a 22,000-pound GBU-43 bomb — known as the “Mother of All Bombs.” Afghan officials estimated that anywhere between 36 and 100 Islamic State fighters were killed after the bomb hit a cave complex used by the Islamic State, but the Pentagon has been reluctant to say why the weapon was used other than it expedited U.S. operations in the area.

The investigation marks the second time the U.S. military has examined a fatal ground raid during the Trump administration. On Jan. 29, Chief Special Warfare Operator William “Ryan” Owens, 36, was killed during a fierce firefight in Yemen involving the elite unit best known as SEAL Team 6. In that case, dozens of civilians were killed after U.S. aircraft opened fire to support U.S. troops who were pinned down under enemy fire, U.S. military officials said.

Davis would not say why the U.S. military opted for a raid in Afghanistan this week rather than another airstrike. Ground attacks — as opposed to airstrikes — allow the assaulting force to gather intelligence from their targets as well as identify those killed.

The deaths of the two Rangers mark the second and third combat deaths in Afghanistan this year. Earlier this month Staff Sgt. Mark R. De Alencar, 37, an Army Special Forces soldier, was killed fighting the Islamic State in the same province.

The Pentagon estimates that there are roughly 800 to 1,000 Islamic State fighters spread across three provinces in Afghanistan. At its height in 2015, the militant group had 3,000 fighters.

The U.S. military has conducted numerous large-scale operations and carried out hundreds of airstrikes against the Islamic State. In March, the militants took responsibility for an attack on a hospital in Kabul that killed dozens of people.

Currently, there are 8,500 U.S. troops in Afghanistan split between supporting Afghan forces fighting the Taliban and conducting counterterrorism operations. There are also 5,000 NATO troops in the country, mostly in advisory roles. The commander of U.S. troops in Afghanistan, Army Gen. John Nicholson, has called for a few thousand more troops to break what he sees as a stalemate with enemy forces in the country.