Taliban insurgents controlled Swat for two years until a massive military operation drove them out in May 2009, but sporadic attacks have continued in the area.
Yousafzai became known in early 2009, when she wrote a diary about Taliban atrocities under a pen name for the BBC's Urdu service. In 2011, the Pakistani government awarded her a 1 million rupee ($10,500) prize and a peace award for her bravery in raising her voice for children's rights and girls' education when few others in Pakistan dared to.
Yousafzai also was nominated for the International Children's Peace Prize in 2011.
The seventh-grader who was wounded in the leg said she and her classmates were leaving school when the attack occurred.
"Two bearded armed men stopped our school van and asked for Malala and opened fire from behind the van," the girl, named Shazia, said from the hospital where she and Yousafzai were first taken.
Ihsanullah Ihsan, chief spokesman for the Pakistani Taliban, said in calls to the media that the militant group targeted Yousafzai because she generated "negative propaganda" about Muslims.
"She considers President Obama as her ideal. Malala is the symbol of the infidels and obscenity," Ihsan said.
Political leaders condemned the attack.
"We have to fight the mind-set that is involved in this. We have to condemn it," Prime Minister Raja Pervez Ashraf told the Pakistani Senate. "Malala is like my daughter and yours, too. If that mind-set prevails, then whose daughter would be safe?"
Yousafzai also is an advocate for literacy in the Swat valley. She started her diary when the Taliban banned girls' education and bombed hundreds of schools, mostly those for girls, in Swat.
Her father, Zia Uddin Yousafzai, is an educator and a member of Swat's peace jirga, or tribal gathering.
"She is all right," he said in an interview. "Please pray for her early recovery and health."
After being forced out of Swat, Pakistani Taliban fighters relocated to the Afghan border region near the eastern Afghan provinces of Konar and Nurestan. They are blamed for attacks on Pakistani forces from across the border.
"This is a highly condemnable act of terror and an attempt to silence a brave voice," Mian Iftikhar Hussain, a spokesman for the northwestern Khyber Pakhtunkhwa government, said.
In her diary, Yousafzai wrote about her fears and growing Taliban influence. One morning, she wore her favorite pink dress. "During the morning assembly we were told not to wear colorful clothes as the Taliban would object to it," she wrote.
In another entry, she wrote: "On my way from school to home I heard a man saying 'I will kill you.' " I hastened my pace and after a while I looked back if the man was still coming behind me. But to my utter relief he was talking on his mobile and must have been threatening someone else . . ."