KABUL, Afghanistan — At least 23 soldiers were killed while they were sleeping on Saturday in an insider attack in eastern Afghanistan, officials said, the latest episode of enemy infiltration that has raised concerns about a new local military force billed as the hope for holding territory recaptured from the Taliban.

The Taliban infiltrator, who was on duty at a military base in Ghazni Province, opened fire on his colleagues, wiping out almost the whole unit, officials said. The attacker then seized all weapons and equipment in the base and joined the insurgency.

The exact number of casualties was unclear. The Afghan Ministry of Defense confirmed the death of nine soldiers, and the Taliban said 32 had been killed, but their claims of casualties are mostly exaggerated.

The figure of 23 came from Esmatullah Jamuradwal, a member of the provincial council, who said that only one soldier, out of 24 in the Territorial Army unit, had survived. “The attacker packed all weapons and ammunition in a Humvee and drove to the Taliban,” he said.