KABUL, Afghanistan — An Afghan soldier arrested in the shooting death of one coalition soldier and the wounding of four others last week escaped from custody Sunday morning after a soldier guarding him devised an elaborate ruse to sneak him out through a military hospital, officials said.

The imprisoned soldier, identified as Lamber Khan, and his guard escaped from an Afghan army base in the southern province of Kandahar, according to Gen. Abdul Hameed, the commander of the Afghan 205th Army Corps.

Hameed said the guard, who was a supervisor, filled out a hospital card for Khan, allowing him to leave the detention wing of the base and visit the military hospital. There, the guard was able to unshackle him, and the two men were able to escape together.

“He was a trustworthy person, and we do not know what made him release the culprit and escape with him,” said Hameed, who noted that the guard was from around the same area as the prisoner, the eastern city of Jalalabad.

The Taliban said Khan, a five-year veteran of the army, had been in touch with them before and after the shooting, but the extremists had opted to remain quiet about it until he could escape and join them.

The International Security Assistance Force, or ISAF as the military coalition is known, said it was aware of the soldier’s escape from an Afghan facility but offered no further details.

That Khan escaped with the help of a fellow soldier underscored the continued animosity within some pockets of the Afghan army toward their trainers and, more broadly, the Western military presence.

While the Taliban claimed credit for the attack, Afghan officials said Khan had indicated to them that he pointed his gun at his ostensible allies out of frustration over continued raids on his village in Nangarhar province.