No insurgent group has so far claimed responsibility for the killings, which highlight growing insecurity after the Taliban sought to overrun Kunduz city for the second time last month.
The soldiers came under fire as they were assisting Afghan troops to clear a Taliban position and disrupt the group's operations in Kunduz, US forces said in a brief statement.
"On behalf of all of US Forces - Afghanistan, today's loss is heartbreaking and we offer our deepest condolences to the families and friends of our service members who lost their lives today," said John Nicholson, the top US and NATO commander in Afghanistan.
The killings come just days before the US presidential election. Hillary Clinton or Donald Trump will inherit America's longest war with no end in sight, with the conflict largely ignored during the bitter election campaign.
More From This Section
The US military, which leads a NATO mission to train and assist the Afghans, often gives upbeat assessments about Afghan military performance.
But as Afghan military forces near the end of a second year leading security operations across their battered country, they are being killed in horrific numbers.
The death toll this year is much worse already, with 5,523 Afghan police and troops killed in the period from January 1 to August 19, according to the US watchdog SIGAR.