A US Navy Seal who was advising Kurdish Peshmerga forces in northern Iraq has been killed by Islamic State (IS) militants, US defence officials say.
The special warfare operator was named as Charlie Keating, aged 31, from the state of Arizona.
Peshmerga officials said the militants breached the frontline north of the IS-held city of Mosul on Tuesday morning.
The American was the third to be killed in combat since the US-led coalition campaign against IS began in 2014.
Although Iraqi pro-government forces have gradually pushed back IS since then with the help of US-led coalition air strikes and military advisers, the jihadist group still controls large parts of the country's north and west.
The Navy Seal's death was announced by US Defence Secretary Ashton Carter, who said only that a serviceman had died as a result of enemy fire near Irbil, the capital of Iraq's Kurdistan Region.
"It is a combat death, of course, and a very sad loss," he told reporters in Germany.
A US military official in Iraq subsequently said he was killed by "direct fire" at a Peshmerga position about 3km to 5km (2-3 miles) behind the frontline after it was penetrated by IS militants.
A Peshmerga spokesman, Maj Gen Jaber Yawer, told the Associated Press that the American was shot dead by an IS sniper near the town of Tal Asqof, about 28km (17 miles) from Mosul.
IS militants overran the town at dawn on Tuesday in an assault that involved a number of truck bombs, but were driven out later in the day by Peshmerga fighters.
The attack on Tal Asqof was part of a major offensive launched by IS militants in northern Iraq, which the group said involved "remotely-guided car bombs".
An Iraqi military source told the BBC that special forces had foiled an attack by five suicide bombers in the village of Khirbirdan, south of Mosul.
A Peshmerga source said an attack on Wardak, east of Mosul, was also repelled.
Arizona Governor Doug Ducey later identified the Navy Seal as 31-year-old Charlie Keating IV - the grandson of a late financier from the state involved in savings and loan scandal in the 1980s.
Gov Ducey ordered all state flags to fly at half-mast on Wednesday in honour of Keating.
There are more than 5,500 US military personnel in Iraq. Some 3,870 are deployed to advise and assist local forces fighting IS militants.
The remainder includes special operations personnel, logistics workers and troops on temporary rotations.
Last month, the US announced that it planned to send 200 additional advisers to Iraq by the end of the year and deploy them closer to the frontlines so that they could assist in the operation to retake Mosul.
In March, US Marine Staff Sgt Louis Cardin was killed in a rocket attack by IS while providing force protection fire support at a coalition firebase near Makhmour, south-west of Mosul, that had only become operational a few days earlier.
US Army Master Sgt Joshua Wheeler died in October during a special forces mission to rescue hostages held at an IS prison near Hawija, west of Kirkuk.