The teenage girl was the hero of a night of carnage that left her family’s hillside home in western Afghanistan strewn with bodies. Qamar Gul, 15, fought to her last bullet, gunning down Taliban attackers who raided the house and killed her father and mother.

In the days after the attack last week, Afghan social media was full of slick posters celebrating her as “My Hero.”

But the story of her heroism is steeped in pain, in a culture that often treats women as property, and in the confusion of an Afghan war that has twisted families into knots of complex loyalties and feuds.

One of the attackers she killed was her own husband, who was fighting on the Taliban’s side and apparently seeking her forcible return after a falling out with her family, according to relatives and local officials.

Ghor province, where the attack happened, has remained restive in recent years and proved particularly brutal for women.

About four years ago, Gul’s father, Shah Gul Rahimi, struck an agreement with a local man from an adjacent village named Mohamed Naeem: Naeem would marry Rahimi’s daughter, Qamar, as his second wife. In exchange, Rahimi would take Naeem’s teenage niece as his second wife.

The trouble seems to have begun when Rahimi’s new wife visited her family and refused to return to her husband. In return, when Qamar Gul came home, her father held her until the family returned his wife and Naeem paid a $3,000 debt for which Rahimi was being harassed.

But Naeem had other thoughts: He had grown close to a ruthless Taliban commander in Ghor who would help him take Qamar Gul home without paying any money. They chose the early hours after midnight on July 17 for a surprise attack, with about a dozen of their fighters surrounding the hillside home and barging in.

When Rahimi came out of the hallway to see what was happening, he was gunned down. When Qamar Gul’s mother, Fatima, came out to cry for help after her husband was shot, she was also killed.

Qamar Gul grabbed her father’s weapon, ran to the doorway and began spraying at the attackers in the yard. She shot two of them dead and wounded the senior Taliban commander. The Taliban fled the scene as neighbors and local militia fighters began arriving.

Two days after the attack, the Ghor provincial governor put out a statement saying Qamar Gul and her 12-year old brother had defeated an “offensive attack” by the “Taliban terrorist group” and forced the “bloodthirsty Taliban to flee, leaving behind two of their dead in the battlefield.”

The statement attached graphic photos of two bodies. One was Naeem, Qamar Gul’s husband, the chest of his embroidered tunic soaked in blood.