Ms Gillard went to Kabul and the Australian base at Tarin Kowt, where she had a barbecue with troops and visited a hospital.
"I wanted to say a big thank you to our troops for everything they're doing in such difficult circumstances," Ms Gillard said.
"We have experienced many losses.
"There has been a lot of heartache.
"But talking to the troops today morale is good and that is a real tribute to them."
Ms Gillard also held talks with Afghan president Hamid Karzai about insider attacks on Australian soldiers.
Australia suffered its deadliest day in combat since the Vietnam War when five troops were killed in two separate incidents in Afghanistan on August 30.
Three of the soldiers were killed in an insider attack, with the five bringing to 38 the number of Australian lives lost in conflict in the region.
"Clearly these have been tragic and disturbing incidents designed to corrode morale," Ms Gillard said.
"Everything needs to be done on the Afghan side to deal with the possibility of insider attacks and so I spoke about that."
Ms Gillard made the stopover after her trip to Bali for the 10th anniversary commemorations of the terrorist bombing.
She has now headed to New Delhi, where talks on the sale of uranium from Australia to India will be high on the agenda.
Last year, Ms Gillard overturned decades of Labor policy by announcing Australia would consider selling uranium to India - a nation armed with nuclear weapons.
It is understood negotiations are progressing but that a deal is at least six months away.
The Greens and many in the Labor Party are opposed to uranium sales.
India's auditor-general warned in August that the country is heading for a disaster of Chernobyl-like proportions unless proper safeguards are installed at its nuclear facilities.
Ms Gillard arrives in India later today.