In a speech to a joint meeting of the U.S. Senate and House of Representatives, Ghani said Afghanistan owes a "profound debt" to the 2,315 U.S. troops killed and the more than 20,000 wounded in the war that began after the Sept. 11, 2001, attacks.
Ghani, who became president last year, has been feted in Washington during a five-day trip to the United States seeking to repair ties frayed under his predecessor, Hamid Karzai.
His address came as Congress has been debating defense spending and other areas of the next U.S. budget. Lawmakers also are considering President Barack Obama's request for authorization of his military campaign against Islamic State, which has met stiff resistance on Capitol Hill.
"Daesh (Islamic State) is already sending advance guards to southern and western Afghanistan to test for vulnerabilities," Ghani said.
He said Afghanistan, whose Taliban government sheltered al Qaeda leader Osama bin Laden, would never again host terrorists. He urged Muslims around the world to speak out against extremism.
"Silence is not acceptable," he said.
As Ghani visited Washington, six people were killed and more than 30 wounded near his palace in Kabul, which is on high alert ahead of the expected Taliban spring offensive.
Ghani called national reconciliation a "pillar" of his government. He said Taliban members could find their way back into Afghan society, if they break from the militant group.
"The Taliban need to choose not to be al Qaeda, and be Afghan," he said.
Lawmakers received Ghani's passionate speech warmly, giving him repeated standing ovations particularly as he pledged to improve conditions for Afghan women.
On Monday, Ghani and Afghan Chief Executive Abdullah Abdullah met at the presidential retreat at Camp David with top U.S. officials, who said Washington would fund Afghan security forces at least into 2017.
On Tuesday, Obama said he would maintain a force of 9,800 in Afghanistan this year while sticking to a 2017 exit plan.
As he thanked the lawmakers for continued support, Ghani promised Afghanistan will become self-reliant soon.
"In this decade we will," he said, in one of the biggest applause lines of his speech.