Prime Minister Stephen Harper hailed the end of Canada鈥檚 military mission in Afghanistan Wednesday as a 鈥渟ignificant milestone in the fight against global terror.鈥

After 12 years, the loss of 162 lives and endless debate at home, the military mission formally ended with a ceremony in Kabul.

Canadian and international dignitaries looked on as the army took down the Canadian flag at NATO headquarters, still under heavy guard in the war-ravaged country.

In a statement, Harper praised the work of the more than 40,000 Canadian Forces members who 鈥渉ave fought to defeat the threat of terrorism, and to ensure the freedom of others to build a stronger, safer world. In the course of this fight, many have paid the ultimate price.

鈥淭heir courage and dedication has brought much pride to our country. I look forward to personally welcoming home the last contingent of Canada鈥檚 brave men and women of the Canadian Armed Forces when they return home on the final flight.鈥

The withdrawal of the last 100 Canadian soldiers, who stayed behind to train Afghan National Security Forces, will be completed over the next few days. The last troops will arrive home on March 18.

鈥淵our strength has protected the weak; your bravery has brought hope to hopeless; and the helping hand you have extended to the Afghan people has given them faith that a better future is within their grasp," Deborah Lyons, the Canadian ambassador to Afghanistan, told the soldiers in Kabul Wednesday.

In a statement, Liberal defence critic Joyce Murray said 鈥渁ll Canadians join in extending our appreciation and thanks鈥 to those who served in Afghanistan.

鈥淎ll those who served have made enormous sacrifices during Canada's largest military deployment since the Second World War,鈥 Murray said.

鈥淐anadian women and men carried out their duties with the utmost professionalism and distinction. We are immensely proud and grateful of their service to enhance peace, stability, and hope in a troubled region of the world.鈥

Canada must be sure to 鈥渢ake the best possible care鈥 of the veterans who are returning or who have already returned from Afghanistan, Murray said.

Today, Canadians remain divided on the success of the Afghan mission. Heavy combat, roadside bombings and other incidents took the lives of 158 Canadian soldiers, one diplomat, one journalist and two civilian contractors. Many soldiers who returned home injured or profoundly changed by the experience are now struggling with post-traumatic stress disorder, inadequate mental health care services, unemployment and other issues.

鈥淭his country was put to the test,鈥 retired Col. Pat Stogran, who served as commander in Afghanistan, told CTV鈥檚 Canada AM Wednesday. 鈥淭he jury is still out right now.鈥

Since Canadian troops first arrived in October 2002, there have been notable improvements in Afghanistan: access to education, especially for girls, a drop in infant and maternal mortality rates, and infrastructure projects, among others.

From 2001 to 2013, Canada spent $1.65 billion on reconstruction and development in Afghanistan and made efforts to improve women鈥檚 rights and the living conditions of rural Afghans.

But security is deteriorating in many parts of the country, raising serious questions about Afghanistan鈥檚 future. Just this week, a British-Swedish journalist was gunned down in a heavily policed part of Kabul. Feday-e-Mahaz, a Taliban splinter group, claimed responsibility for the killing.

Access to health care is another big problem. Diseases such as polio, malaria, measles and tuberculosis are a huge burden on the underfunded health care system. 

Stogran, an outspoken former veterans鈥 affairs ombudsman, said he left the army 鈥渄iscouraged鈥 by what he called a 鈥渇alling apart鈥 of the Canadian government鈥檚 approach to the Afghan mission. But he remains 鈥渧ery proud鈥 of the soldiers鈥 accomplishments and sacrifices.

鈥淚鈥檓 amazed at how our young people rallied to the call and the job our folks did overseas,鈥 he said. Not only did Canadian soldiers risk their lives every day, they also collected money for aid projects and helped build schools and wells, Stogran said.

The removal of the Canadian flag in Kabul was 鈥渁 very solemn occasion for me,鈥 he said. But ongoing conflicts in the Middle East mean that 鈥渨e鈥檙e not finished this yet,鈥 he added.

鈥淲e are at a point now where our nation has to heal and we have to celebrate the accomplishments of our young people. They鈥檝e planted a seed in Afghanistan that we should all hope and pray will serve the long-term benefit of a very troubled nation,鈥 Stogran said.

鈥淏ut we can鈥檛 dust ourselves off and say: 鈥榃ell, I鈥檓 glad that Afghanistan is over with.鈥欌

NATO鈥檚 combat forces are also scheduled to leave Afghanistan at the end of the year, but member nations have promised $4.1 billion a year in funding for the country鈥檚 security forces.

Lyons, the Canadian ambassador, said Wednesday that Canada will remain involved in building Afghanistan鈥檚 economy, particularly the resource sector.

In his statement, the prime minister reiterated that Canada 鈥渨ill continue to play an important role in supporting efforts that contribute to building a better future for all Afghans.鈥

Harper also said that when he greets the last soldiers as they return home, he will announce plans to 鈥渇ormally commemorate the mission in Afghanistan.鈥

With files from The Canadian Press