WASHINGTON — The United States and Afghanistan began talks Thursday on a security agreement that would authorize a U.S. troop presence in Afghanistan after 2014, when Afghan forces are to assume responsibility for the war.

Gen. Joseph Dunford Jr., the Marine officer who has been nominated by President Barack Obama to assume command of the military mission in Afghanistan next year, told Congress that the goal was to complete the talks by May 2013, well ahead of the deadline for handing responsibility to the Afghans. The timetable, he noted, is longer than the one the Obama administration set during its failed effort to negotiate a similar agreement with Iraq.

“I think one of the critical lessons learned is that we need to allow sufficient time for negotiations to be complete,” the general told the Senate Armed Services Committee on Thursday.

The 2011 talks between the U.S. and Iraq ultimately failed over the U.S. demand that a status of forces agreement be approved by the Iraqi Parliament, a step the administration said was needed to provide legal immunity for U.S. troops. But the limited time to sort out thorny political and legal issues was a complication: Obama formally opened the Iraq negotiations in June 2011, less than seven months before the deadline for U.S. troops to leave the country if a new accord was not reached.

The talks between the U.S. and Afghanistan are being led by James Warlick, the deputy special representative for Afghanistan and Pakistan, and Eklil Ahmad Hakimi, Afghanistan’s ambassador in Washington.

Assuming the necessary agreements can be reached, the U.S. and NATO are planning to keep a modest force in Afghanistan after 2014 to guard against terrorist threats and advise Afghan forces.

A successful negotiation, Dunford said, would send a message to the Afghans and to their neighbors that the U.S. was not abandoning Afghanistan. “Pakistan hedges its bets based on what they believe our long-term commitment to the region would be,” he said.

But even lawmakers who back the Afghan mission, like Sen. Lindsey Graham, R-S.C., have said they would not support continued deployment unless the accord gives U.S. troops immunity from prosecution in Afghan courts.

If confirmed, which is considered very likely, Dunford would take command from Gen. John R. Allen, who is scheduled to stay in charge until the change of command in February.