Brent Taylor, 39, had taken a year-long leave of absence as mayor of North Ogden, north of Salt Lake City, for his deployment to Afghanistan.
He was a military intelligence officer with Joint Force Headquarters and was expected to return to his mayoral job in January.
Another US military member, whose name was not immediately made public, was wounded in Saturday’s attack that killed Major Taylor, who died from wounds from small arms fire, military officials said.
Major General Jefferson S. Burton of the Utah National Guard, said Major Taylor’s mission was helping to train and build the capacity of the Afghan National Army.
“He was with folks he was helping and training. That’s what’s so painful about this. It’s bitter,” Major General Burton said.
“I do believe that Major Taylor felt he was among friends, with people he was working with.”
Utah media outlets cited a statement from NATO saying Major Taylor was shot by one of the commandos being trained and that the attacker was killed by Afghan forces.
Major Taylor, who served two tours in Iraq and was on his second tour in Afghanistan, leaves behind a wife and seven children.
Hundreds of residents of North Ogden lined the streets to see him off prior to his latest deployment.
Utah Governor Gary Herbert called his death, “a sad day for Utah, for America”.
On Twitter, Utah Senator Orrin Hatch called Major Taylor, “a hero, a patriot, a wonderful father, and a dear friend”.
“News of his death in Afghanistan is devastating,” he wrote.
Major Taylor became the city’s mayor in 2013. His remains are scheduled to arrive at Dover Air Force Base in Delaware on Monday evening (local time).