Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

The two American service members killed during an anti-ISIS operation in Afghanistan this week came under attack in an intense, three-hour long shootout and may have fallen victim to friendly fire, the Pentagon said.

An investigation was underway Friday into the possible cause of death, Pentagon spokesman Capt. Jeff Davis said.

Military officials also identified the two U.S. Army Rangers killed as Sgt. Joshua Rodgers, 22, of Bloomington, Illinois, and Sgt. Cameron Thomas, 23, of Kettering, Ohio. They were both assigned to the 3rd Battalion, 75th Ranger Regiment in Fort Benning, Georgia, and on their third deployments.

U.S. forces had teamed with Afghan fighters to target an ISIS compound and tunnel complex. The mission occurred in the Momand Valley — the same location where earlier this month the U.S. dropped the largest non-nuclear weapon ever used, also known as the "mother of all bombs."

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

Wednesday night's skirmish in Nangarhar province, a remote area along the border with Pakistan, involved about 50 U.S. Army Rangers and 40 Afghan commandos.

Once at the heavily fortified compound, the unit was immediately met by gunfire from all directions, Davis said.

Two of the Rangers were hit and died later of their injuries, while a third was grazed by a bullet. He is expected to recover, senior U.S. military officials told NBC News.

The forces were after Abdul Hasib, the emir for all of ISIS in Afghanistan. The U.S. military believes he is still alive, but doesn't know for certain, Davis said.

Sgt. Joshua P. Rodgers, left, and Sgt. Cameron H. Thomas were killed while conducting combat operations in Nangarhar Province, Afghanistan. U.S. Amry

Officials believe 35 ISIS fighters were killed and their leader of the regional affiliate known as ISIS-K is also believed to be dead.

"If confirmed, the death of the Emir and his associates will significantly degrade ISIS-K operations in Afghanistan and help reach our goal of destroying them in 2017," the Pentagon said in a statement.

Amid the frenzy of the shooting, the Americans called in air support from Lockheed AC-130 gunships, Apache helicopters and F-16 fighter jets.

"The fight against ISIS-K is important for the world, but sadly, it is not without sacrifice," Gen. John Nicholson, the top U.S. commander in Afghanistan, said in a statement Thursday.

Afghanistan has been thrown into turmoil since the Taliban was toppled in the 2001 U.S.-led invasion. The group in recent years has clashed with ISIS over influence and territory, while Afghan and coalition forces wage a larger fight to suppress the militants.

U.S. military leaders under the Trump administration continue to hammer out recommendations for how best to handle Afghanistan, where about 8,400 U.S. personnel serve.