Mr Brown addressed troops during a 90-minute stop at Camp Bastion
Gordon Brown is in Afghanistan on a surprise visit to British troops, en route to the Olympics in Beijing.
The PM told troops at Camp Bastion, the main British base in Helmand, that they were "the heroes of our country".
He told members of 16 Air Assault Brigade they were in the "front line in the fight against the Taleban".
He also paid tribute to Cpl Barry Dempsey, the latest British soldier to die, before holding talks in Kabul with Afghan President Hamid Karzai.
Mr Brown spent 90 minutes at Camp Bastion and visited a field hospital where he spoke to six injured soldiers.
His visit comes as three Nato troops have died in Ghazni province. This week 10 French soldiers died in a Taleban attack.
In a joint press conference with President Karzai later, Mr Brown said the deaths had been a tragedy but the events had only made them "even more resolute ... to defeat the forces of terrorism".
Gordon Brown addresses troops while in Afghanistan
"We understand that in Afghanistan, the front line against the Taleban, what happens in Afghanistan affects the rest of the world," he said.
Mr Brown said there was still "a long way to go" but progress had been made and said Britain would put more resources into training the Afghan national army, which he said may need to be doubled to 120,000.
'Hearts and minds'
He said work would continue to ensure Afghan police were "corruption free" and to improve local and national government administration - by developing a civil service in Afghanistan and more money would be put into improving education.
And $17m (£9m) would go towards funding a radio station to counter the Taleban's message and win "hearts and minds", Mr Brown said.
Earlier, speaking to troops from 16 Air Assault Brigade, Mr Brown said: "You know that by what you are doing here you prevent terrorism coming to the streets of Britain."
He said their work was part of creating a democratic and "terrorist-free" Afghanistan.
Mr Brown also likened the achievements of the British forces to the UK's Olympic medallists in Beijing.
"This week we are celebrating the Olympics where we have had great success," he said.
"But this week also I believe that our Olympic athletes and everybody else in our country will remember that you have showed exactly the same courage, professionalism and dedication.
"You make our country proud every day of the week and every week of the year. You are truly the heroes of our country. I wish to say how proud I am of you today."
Mr Brown said the Taleban had switched to guerrilla-style tactics, like suicide bombs and roadside explosions, rather than "head on confrontation" with troops and he said British commanders had told him they were making "substantial progress" against them.
He said a summer offensive by the Taleban had been expected after a relatively quiet spring.
Since 2001, 116 UK troops have died in Afghanistan, the latest, Cpl Dempsey was killed by a roadside bomb in Helmand on Monday.
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.