The world is safer from terrorism now than when the United States was attacked almost 20 years ago, Prime Minister Scott Morrison says.
Mr Morrison used a speech at the Anzac Day dawn service in Canberra to pay tribute to the "bravest of this generation" who served in Afghanistan during Australia's longest war.
"The world is safer from the threat of terrorism than when the twin towers were felled almost 20 years ago - but we remain vigilant," Mr Morrison said.
"However, this has come at great cost.
"Forty-one Australian lives lost in Afghanistan, whom we especially remember and honour this morning.
"More than 39,000 Australians have served on operations in support of Australia's mission in Afghanistan, many carrying the wounds and scars of war, seen and unseen. They are the bravest of this generation."
He said Australians also honoured the "children, spouses, partners, parents and loved ones" of those who served in Afghanistan.
Labor defence spokesman Brendan O'Connor said that when the war began there were fears Afghanistan, if unchecked, would become a haven for terrorism.
"And whilst there is no perfect way to end a war, or certainly withdrawing forces, I think we're doing the right thing following a decision of the United States to withdraw," he said.
He said Australia should continue to provide support and advice to maintain as much sustainability as possible.
"That is the reason we went in, to stop that haven for terrorism developing that would have been a great threat to many parts of the world.
Defence Minister Peter Dutton said if there was an ongoing issue with the Taliban or a major terrorist attack "we will do whoever is humanly and legally possible to keep our people safe".
Asked whether that meant sending troops back into Afghanistan, he told the ABC: "I think it is very unlikely."
"I can't see how that's possible in the foreseeable future. I think there would be a different way of dealing with those threats than troops on the ground."
Veterans Affairs Minister Darren Chester said there had been "significant achievements" in Afghanistan.
"Hopefully there will be education, health and improved conditions of life, particularly for women in Afghanistan," he told the ABC.
He said "time will tell" whether the achievements would last.
"But the overwhelming majority of Australians who served in Afghanistan have served with enormous integrity, and a great deal of compassion for the population they were seeking to protect and they can be proud of that service."
Despite the Afghanistan withdrawal later this year, there are still 850 personnel serving in the Middle East region.
"There's a range of operations and activities we're contributing to. Whether it is to help some nations build their capacity to provide security and counter-terrorism in their nations or to provide peacekeeping services," Middle East commander Rear Admiral Michael Rothwell said.
Anzac Day at the Middle East operations headquarters would be a "normal day on operations", he said, but would be marked with a dawn service, traditional Aussie barbecue, two-up games and watching sport.
Australian Associated Press