KABUL, Afghanistan – The Taliban and the U.S. said Tuesday they will hold talks on finding a political solution to ending nearly 12 years of war in Afghanistan, as the international coalition formally handed over control of the country’s security to the Afghan army and police.

The Taliban met a key U.S. demand by pledging not to use Afghanistan as a base to threaten other countries, although the Americans said they must also denounce al-Qaida.

But President Obama cautioned that the process won’t be quick or easy. He described the opening of a Taliban political office in the Gulf nation of Qatar as an “important first step toward reconciliation” between the Islamic militants and the government of Afghanistan, and predicted there will be bumps along the way.

Obama, who was attending the G-8 summit in Northern Ireland, praised Afghan President Hamid Karzai for taking a courageous step by sending representatives to discuss peace with the Taliban.

“It’s good news. We’re very pleased with what has taken place,” U.S. Secretary of State John Kerry said in Washington. British Prime Minister David Cameron, whose country has the second-largest contingent of troops in Afghanistan after the U.S., called opening the office “the right thing to do.”

Officials with the Obama administration said the office in the capital of Doha was the first step toward the ultimate U.S.-Afghan goal of a full Taliban renunciation of links with al-Qaida, the reason why America invaded the country on Oct. 7, 2001, shortly after the Sept. 11 attacks against the U.S.

The officials, who spoke on condition of anonymity because they were not authorized to speak on the record, said U.S. representatives will begin formal meetings with the Taliban in Qatar in a few days.

The top U.S. commander in Afghanistan, Marine Gen. Joseph Dunford, said the only way to end the war was through a political solution.

“My perspective has always been that this war is going to have to end with political reconciliation, and so I frankly would be supportive of any positive movement in terms of reconciliation, particularly an Afghan-led and an Afghan-owned process that would bring reconciliation between the Afghan people and the Taliban in the context of the Afghan constitution,” he said.

Dunford added that he was no longer responsible for the security of the country now that Afghan forces had taken the lead.

“Last week I was responsible for security here in Afghanistan,” he said, adding that now it was Karzai’s job. “It’s not just a statement of intent — it’s a statement of fact.”

The transition to Afghan-led security means U.S. and other foreign combat troops will not be directly fighting the insurgency, but will advise and back up as needed with air support and medical evacuations.

The handover paves the way for the departure of coalition forces — currently about 100,000 troops from 48 countries, including 66,000 Americans. By the end of the year, the NATO force will be halved. At the end of 2014, all combat troops will have left and will be replaced, if approved by the Afghan government, by a much smaller force that will only train and advise.

The Taliban emerged from the Pakistani-trained mujahedeen, or holy warriors, who battled the Soviet Union’s occupation of Afghanistan in the 1980s with secret backing by the CIA. Civil war broke out when the pro-Soviet Afghan government collapsed following the departure of Moscow’s troops. The U.S. took an arm’s-length position of neutrality as rival warlords shelled Kabul into ruins.

By 1994, the Taliban had evolved into a united military and political force and in 1996, the group took control of Afghanistan. Led by Mullah Mohammed Omar, the Afghan Taliban sheltered Osama bin Laden in the years leading up to the Sept. 11 attacks in 2001, but the group was toppled shortly after the U.S. and allied invasion one month later.

The U.S.-led invasion leveraged the firepower of factions, such as the Northern Alliance, who had held out against the Taliban after it seized power in 1996. CIA and U.S. special operations support for anti-Taliban forces enabled the U.S. to oust the Islamists by December 2001 without committing large numbers of U.S. ground troops, and the group appeared to have been defeated as a military threat. However, by 2005, the Taliban was beginning to make a comeback, showing signs of improved training and equipment, while using territory inside Pakistan as a sanctuary.

On Monday, Taliban spokesman Mohammad Naim said the Islamic Emirate of Afghanistan, as the Taliban was known when it ruled the country, was willing to use all legal means to end what it called the occupation of Afghanistan. He did not say it would stop fighting at once.