Insurgents in the central province of Ghor stormed the home of teenager Qamar Gul last week looking for her father, the village chief, before shooting her parents.
Gul then emerged from the house with her family's AK-47 and opened fire, killing the two Taliban fighters who gunned down her mother and father and injuring several others.
Her father was a government supporter, which is why the Taliban fighters went to his house and dragged him out.
When his wife resisted, the Taliban fighters killed the couple outside their home, local police chief Habiburahman Malekzada said.
'Qamar Gul, who was inside the house, took an AK-47 gun the family had and first shot dead the two Taliban fighters who killed her parents, and then injured a few others,' he said.
Gul is aged between 14 and 16, according to different officials. It is common for many Afghans to not know their precise age.
Several other Taliban fighters later came to attack her house, but some villagers and pro-government militiamen expelled them after a gunfight.
Afghan security forces have now taken Gul and her younger brother to a safer place, said Mohamed Aref Aber, spokesman to the provincial governor.
Since the incident, social media networks have been flooded with praise for Gul's 'heroic' act.
A photograph of Gul, wearing a headscarf and holding a machine gun across her lap has gone viral in the past few days.
'Hats off to her courage! Well done,' wrote Najiba Rahmi on Facebook. 'Power of an Afghan girl,' wrote another Facebook user Fazila Alizada.
'We know parents are irreplaceable, but your revenge will give you relative peace,' said Mohamed Saleh in his post on Facebook.
The Taliban regularly kill villagers who they suspect of being informers for the government or security forces.
In recent months, the militants have also stepped up their attacks against security forces despite agreeing to peace talks with Kabul.