Nobel Peace Prize winner Malala Yousafzai has ended a surprise visit to Pakistan, her first since being shot in 2012 by Taliban militants who tried to kill her for promoting girls’ education.

A smiling Ms Yousafzai was seen with her parents at Benazir Bhutto International Airport before they boarded a plane to return to London after the four-day visit.

Amid tight security, Ms Yousafzai left her hotel in Islamabad, where she had stayed for four days, and headed to the airport in a convoy of vehicles.

Touching scenes were witnessed when the 20-year-old university student left the hotel, thanking Pakistani officials for giving her an army helicopter over the weekend to fly to the Swat Valley, once virtually under the control of militants, to see her home in the north-west town of Mingora.

After visiting Mingora on Saturday, Ms Yousafzai said in a tweet it was “the most beautiful place on earth” for her.

“So much joy seeing my family home, visiting friends and putting my feet on this soil again,” Ms Yousafzai said as she posted a picture showing her standing with her father, mother and brothers.

Ms Yousafzai said she had waited for the moment for more than five years and said she often looked at Pakistan on the map, hoping to return.

She said she plans to permanently return to Pakistan after completing her studies in Britain.

On Monday, Ms Yousafzai’s uncle Mahmoodul Hassan told the Associated Press that “she is leaving Pakistan with good and memorable memories, but is going back to England because she wants to complete her education there”.

During her visit, Ms Yousafzai also met with Prime Minister Shahid Khaqan Abbasi.

She attended a reception at Mr Abbasi’s office and made an emotional speech in which she said it was one of the happiest days of her life to be back in her country.

Most Pakistanis warmly welcomed Ms Yousafzai’s visit but some launched a campaign on social media against her and she also faced tough questions from journalists, asking about the campaign.

Ms Yousafzai said she failed to understand why she was being subjected to this kind of criticism by educated people.

“We want to work for the education of children and make it possible that every girl in Pakistan receives a high-level education and she can fulfil her dreams and become a part of society,” she told Pakistan’s ARY news channel.

Her home town of Mingora is not far away from the village of Mullah Fazlullah, the head of the Pakistani Taliban who dispatched attackers in 2012 to kill Ms Yousafzai, at the time already a known teenage activist for girls’ education, but she miraculously survived a bullet wound to the head.

Fazlullah had taken over Swat in 2007, marking the height of the militant’s strength there.

The Pakistani military later mostly evicted the militants from the valley and now Fazlullah is believed to be hiding in Afghanistan.

Since her attack and recovery, Ms Yousafzai has led the Malala Fund, which helps students in Swat and elsewhere.