Yousufzai became famous for speaking out against the Pakistani Taliban at a time when even the government seemed to be appeasing the hardline Islamists.
The government agreed to a ceasefire with the Taliban in Swat in early 2009, effectively recognising insurgent control of the valley whose lakes and mountains had long been a tourist attraction.
The Taliban set up courts, executed residents and closed girls' schools, including the one that Yousufzai attended. A documentary team filmed her weeping as she explained her ambition to be a doctor.
"My friend came to me and said, 'for God's sake, answer me honestly, is our school going to be attacked by the Taliban?',"
Yousufzai, then 11, wrote in a blog published by the BBC.
"During the morning assembly we were told not to wear colourful clothes as the Taliban would object."
The army launched an offensive and retook control of Swat later that year, and Yousufzai later received the country's highest civilian award. She was also nominated for international awards for child activists.
Since then, she has received numerous threats. On Tuesday, gunmen arrived at her school and asked for her by name, witnesses told police. Yousufzai was shot when she came out of class and went to a bus.
Taliban spokesman Ehsanullah Ehsan said his group was behind the shooting.
"She was pro-West, she was speaking against Taliban and she was calling President Obama her ideal leader," Ehsan said by telephone from an undisclosed location.
"She was young but she was promoting Western culture in Pashtun areas," he said, referring the main ethnic group in northwest Pakistan and southern and eastern Afghanistan. Most members of the Taliban come from conservative Pashtun tribes.
Doctors were struggling to save Yousufzai, said Lal Noor, a doctor at the Saidu Sharif Teaching Hospital in the Swat valley's main town of Mingora.
(Writing by Katharine Houreld; Editing by Robert Birsel)