Afghan President Ashraf Ghani has thanked the United States for its involvement in what has become the longest foreign war in U.S. history.

"We owe a profound debt to the 2,315 servicemen and women killed and the more than 20,000 who have been wounded in service to your country and ours," he said, speaking in front of a joint session of the U.S. Congress on March 25.

The White House had announced the previous day that it would halt the drawdown of U.S. troops from Afghanistan, maintaining 9,800 troops through the end of 2015.

Ghani also thanked Washington for development aid and other civilian assistance to Afghanistan.

He also called the Islamic State (IS) group a "terrible threat" to the countries of Western and Central Asia, adding that IS fighters had already been sent to Afghanistan "to test for vulnerabilities."

Ghani said that such groups are looking for new havens.

He said that "terrorist movements whose goal is to destabilize every state in the region are looking for new bases of operation."

Ghani added that "We are the frontline, but the terrorists neither recognize boundaries nor require passports to spread their messages of hate and discord."

He said that "to date, Afghanistan's people have rejected the violent [IS] movement. We are willing to speak truth to terror."

Ghani vowed that Afghanistan will never again be a haven for Al-Qaeda or other terrorist groups.

Ghani was received warmly by congressional members.

But his reception was not as enthusiastic as that of Israeli Prime Minister Benjamin Netanyahu, who spoke to Congress on March 3.

Ghani's gratitude towards the United States contrasted with that of his predecessor, Hamid Karzai, who had a rocky relationship with U.S. President Barack Obama.

Karzai said late in his term as president that he saw "no good" in the U.S. presence in Afghanistan and repeatedly refused to sign a bilateral security agreement with the United States, which Ghani promptly signed upon taking office in September.

Ghani thanked a broad section of American society: "We [Afghans] owe a profound debt to the many Americans who have come to build schools, repair wells, and cure the sick. And we must acknowledge with appreciation that at the end of the day it is the ordinary Americans whose hard-earned taxes have over the years built the partnership that has led to our conversation today."

He also touted Afghanistan's goal of self-reliance, which he defended as "no pipe dream."

"We don't want your charity. We have no more interest in perpetuating a childish dependence than you have in being saddled with a poor family member, who lacks the energy and drive to get out and find a job. We're not going to be the lazy Uncle Joe," he told Congress, eliciting laughs.