Hamid Karzai, who stepped down as president yesterday, refused to sign the deal in a disagreement that symbolised the breakdown of Afghan-US relations after the optimism of 2001 when the Taliban were ousted from power.
Afghan National Security Adviser Hanif Atmar and US Ambassador James Cunningham inked the document at a ceremony in the presidential palace in Kabul as Ghani stood behind the pair looking on.
"It shows the president's commitment to the Afghan security forces and confidence in our future relationship with the US. We are replacing uncertainty with certainty."
US State Department spokeswoman Jen Psaki said the deal would "enable Afghanistan, the United States and the international community to maintain the partnership we've established to ensure Afghanistan maintains and extends the gains of the past decade."
More From This Section
US-led NATO combat troops are due to withdraw by the end of this year, lending added urgency to reaching an agreement on a residual force.
Troops from Germany, Italy and other NATO members will join a force of 9,800 US soldiers, bringing numbers up to about 12,500.
The new mission - named Resolute Support - will focus on training and supporting the Afghan army and police as they take on the Taliban insurgents.
Negotiations over the pact saw Karzai at his most unpredictable as he added new demands, shifted positions and infuriated the United States, Afghanistan's biggest donor.
He eventually refused to sign the agreement despite a "loya jirga" grand assembly which he convened voting for him to do so. There was also widespread public support for US troops to stay.