WASHINGTON — The military will charge Army Staff Sgt. Robert Bales with 17 counts of murder stemming from a massacre of Afghan villagers, a U.S. official said Thursday.

Bales, 38, who is based at Joint Base Lewis-McChord, will be formally charged Friday, the official said. He has been detained at a maximum-security military prison at Fort Leavenworth, Kan., for the past week.

The killings have roiled relations between the United States and Afghanistan at a time U.S. commanders are seeking to stabilize the country in preparation for an eventual U.S. exit. President Obama has promised to hold accountable “anyone responsible” for the killings.

The murder charges indicate Army prosecutors have concluded that the slayings were premeditated and that Bales, of Lake Tapps, was fully aware of his actions. His civilian attorney, John Henry Browne of Seattle, has said his client does not remember much about what happened during the March 11 massacre.

Military authorities had originally said Bales, the married father of two children, was suspected of killing 16 Afghan villagers: nine children and seven adults. They changed that Thursday to 17, raising the number of adults by one but without explaining how the change came about.

It’s possible some of the dead were buried before U.S. military officials arrived at the scene of the carnage. The slayings occurred in two villages in the Panjwai District of Kandahar province in southern Afghanistan.

Although Afghan President Hamid Karzai relies on the U.S. and NATO military coalition to hold the Taliban-led insurgency at bay, he referred to foreign troops as “demons” after the massacre. He also demanded that they withdraw from villages across the country, which would upend the U.S. military’s counterinsurgency strategy.

Bales also will be charged with six counts of attempted murder and aggravated assault in the woundings of six other villagers, and dereliction of duty, said the U.S. official, speaking on the condition of anonymity.

Browne said he wouldn’t comment on the charges because he had not been officially provided a copy. He said he spoke Thursday with prosecutors, who told him they will formally present the charges Friday.

The attacks came at a time of evaporating trust between the U.S. military and its Afghan allies.

In January, an Internet video depicted U.S. Marines urinating on the corpses of purported Taliban fighters. Soon after, U.S. troops inadvertently burned copies of the Quran and other holy texts, sparking widespread riots.

Meanwhile, Afghan soldiers and others have stepped up attacks on U.S. troops, including the slaying of two U.S. officers assigned to the high-security Afghan Interior Ministry. Last week, an Afghan interpreter working for NATO hijacked a truck, immolated himself and tried to run down a crowd of high-ranking Marines waiting to greet Defense Secretary Leon Panetta as his plane landed in Helmand province.

Military officials have not offered a motive for the Kandahar killings but have said they are investigating whether Bales was drinking before the attacks.

Bales was involved in at least three separate incidents in which alcohol appears to have been a factor.

According to a 2002 Tacoma police report, Bales was charged with assault in a fracas at a casino. He allegedly punched a security guard in the chest when two bouncers tried to evict him after another customer said he had made a threat. The guards told police Bales was intoxicated.

In 2008, Bales struck a traffic sign and a tree when he rolled his red Mustang on a road near his house. Witnesses said he was bleeding profusely and smelled of alcohol when he fled into woods. He called police more than 10 hours later and said he had fallen asleep at the wheel, but no blood test was done to determine whether he had been drinking. Court records show he was fined $792.50 for hit-and-run and property damage.

The Associated Press reported Thursday that in 2008, Bales was accused of shaking hands with a woman outside a Tacoma bowling alley, telling her she was beautiful, pulling her hand to his crotch and then punching and kicking her boyfriend. A Pierce County sheriff’s deputy described Bales as “extremely intoxicated” in an incident report about the fracas at the Paradise Bowl.

The woman and her boyfriend also were drunk, to the point of mumbling and slurring their speech, according to the deputy.

The case was referred to prosecutors, but no charges were brought.

Browne has declined to discuss assault accusations because he said they have no bearing on the Afghanistan matter.

Bales’ legal proceedings could last years.

Material from The Associated Press and The New York Times is included in this report.