Leaders of Nato's 28 states have backed a strategy to transfer leadership for the fight against the Taliban to Afghan forces by the end of 2014.
Afghanistan President Hamid Karzai was in Lisbon, where he signed a long-term security partnership with Nato.
Nato's secretary general said the Taliban would not be allowed simply to wait for foreign forces to leave, saying Nato would remain committed.
Nato would stay "as long as it takes", Anders Fogh Rasmussen said.
The Afghan delegation and Nato leaders held several hours of talks on Saturday morning.
In front of the world's media, President Karzai and Mr Rasmussen then signed a formal partnership that Nato says will codify its commitment to Afghanistan for years to come.
Despite agreeing to transfer military control to Afghanistan by 2014, he remained clear that this would not be a signal for the Taliban to claim victory.
"One thing must be very clear - Nato is in this for the long term," he said.
"We will not transition until our Afghan partners are ready. We will stay after transition in a supporting role.
"If the enemies of Afghanistan have the idea that they can wait it out until we leave, they have the wrong idea. We will stay as long as it takes to finish our job."
Mr Karzai said the decision to transfer military control would give every Afghan a stake in the future of their country.
He hoped that in future "Afghanistan will be [a country] contributing to world security and economy rather than one that will be a burden".
President Karzai said he had thanked Nato for the sacrifices made by its soldiers, but had also raised concerns.
"I also informed them of the concerns of the Afghan people with regard to civilian casualties, with regard to detentions, with regard to, at times, Nato's posture."
Nato's International Security Assistance Force (Isaf) has some 130,000 soldiers based in Afghanistan, most of them from the US.
Under the new plan there would still be a role for Isaf troops in the country in 2015 and onwards, but that would largely be in training Afghan forces.
Global role
The two-day Lisbon summit has been billed as one of the most important in the alliance's history, as it seeks to update its strategy and structure to face new security threats.
On Friday member states agreed a new 10-year "strategic concept", a document that defines the fundamental nature of Nato's role in the world.
The draining, ongoing conflict in Afghanistan had prompted suggestions that Nato would retreat from explicit commitments to a global defence role.
However, the document agreed on Friday commits Nato members "to defend one another against attack, including against new threats to the safety of our citizens", without defining a geographical limit to its theatre of operations.
The alliance would also seek to "create the conditions" for a world without nuclear weapons, but until that goal was in sight would remain a nuclear-armed organisation.
That decision will see US nuclear weapons remain in Europe despite calls from Germany and some other members for Mr Obama to pull them out.
Separately, member states reached an agreement to develop and deploy defences against ballistic missile attack on their territories.
Mr Obama said the agreement "responds to the threats of our times" and would benefit all Nato citizens.
"For the first time, we have agreed to develop a missile defence capability that's strong enough to cover all Nato European territory and populations, as well as the United States," he said.
Nato hopes Russia - a long-term opponent of previous US missile defence plans - will also agree to join the project, and will speak about the issue with Mr Medvedev on Saturday.
But the BBC's diplomatic correspondent Jonathan Marcus says that bringing Russia on board will not be easy - Moscow has rejected all previous invitations over fears its own missile force might be compromised.
Russian President Dmitry Medvedev is due to address the summit on Saturday.