Carter's visit came just days after the United States and NATO pledged to keep thousands of troops in the troubled country, a move warmly welcomed by President Ashraf Ghani, who said it highlighted an "environment of trust" between Washington and Kabul.
Local forces have been providing security in Afghanistan since the start of 2015, when they took over from NATO combat troops.
More than 5,000 Afghan police and troops died last year alone, and they have confronted multiple challenges apart from just the Taliban -- including attacks from the ISIS and Al-Qaeda.
The Taliban claimed responsibility last month for a suicide attack that killed more than 30 Afghan police cadets in Kabul.
"The Afghan security forces have demonstrated the motivation, the will and the resilience in the face of a persistent enemy," Carter said at the news conference in the presidential palace with Ghani.
"I commend them for fighting courageously last year during a tough fighting season."
Speaking later to US troops at Bagram air base, however, Carter stressed that without continued international financial and military support, "Afghan forces aren't going to be able to solidify their control over the country".
'New Rules Of Engagement'
President Barack Obama, elected eight years ago on a pledge to end the wars in Afghanistan and Iraq, has been unable to do so given the fragile security situations in both countries.
Last week he reined in plans to cut US troop numbers in Afghanistan from 9,800 to 5,500 by the end of the year.
Instead, around 8,400 US troops will remain, mostly working under the NATO banner as trainers and "enablers", with about a quarter specialising in counter-terrorism operations.
Obama has also relaxed the rules of engagement, making it easier for US troops to proactively target the Taliban and assist Afghan forces, instead of waiting to respond to an attack.
Carter said the new rules have helped the Afghan troops, while top US general in Afghanistan John Nicholson said the US had been using these new powers almost daily, including around the northern city of Kunduz, which Taliban fighters briefly seized last year.
"With the new authorities that we have, (we can) provide combat enablers to assist the Afghans who are now expanding the zone that they control around Kunduz, taking the initiative against the enemy," Nicholson told reporters.
He added that US forces had also supported Afghans in the south, and were shifting attention to Nangahar province and areas to the east.
Carter's unannounced visit follows a renewed commitment to Afghanistan from NATO, which said over the weekend it would keep forces there until the end of 2017 at least.
The international alliance has about 13,000 service members in Afghanistan -- mostly American -- under its Resolute Support training mission and expects about that number next year. NATO also pledged funding through to 2020.
Despite a massive, nearly 15-year international effort to defeat the Taliban, the resurgent group controls large areas of Afghanistan and has vowed to keep fighting until foreign forces leave.
Further complicating matters is endemic corruption and allegations of rights abuses, and NATO is demanding broad reforms.
"Corruption is as dangerous as terrorism," Ghani said Tuesday, vowing to account for every penny "with full transparency".
Both Carter and Ghani also addressed the role of Afghanistan's neighbour Pakistan, long accused by Kabul of sponsoring militants including the Taliban.
Taliban chief Mullah Akhtar Mansour was killed by a US drone in Pakistan earlier this year in a strike that Islamabad said violated its sovereignty.
But Carter, while stressing the US would work with Pakistan "wherever it can" on extremism, warned that Washington would "continue to target and strike terrorist leaders everywhere in the world where they might threaten Americans or our interests and our friends".
"Pakistan has a fundamental decision to make," added Ghani, who has loudly demanded in the past that Pakistan take action against the Taliban. "There is no difference between good terrorists and bad terrorists."
Carter's visit followed a brief trip to Baghdad on Monday, where he pledged hundreds of additional US troops to assist Iraqis fighting the ISIS group.
(This story has not been edited by NDTV staff and is auto-generated from a syndicated feed.)