WASHINGTON — US and Afghan officials are weeks away from clinching a security pact allowing an American military mission to stay in Afghanistan beyond 2014, Defense Secretary Leon Panetta said Tuesday.

The two sides still had to resolve disagreements over controversial night raids by US troops, which Afghan President Hamid Karzai and other officials say have claimed too many civilian lives, and the transfer of US-run prisons in the country, the Pentagon chief said.

"As you know, there are two areas that we still have difficulties with, one of which involves the transfer of detention facilities, the other involves night-time raids," Panetta told the Senate Armed Services Committee.

"And we continue to try to see if we can work out some kind of compromise on those issues," he said.

But he said most of the elements of a security pact were in place.

"So I'm confident that hopefully, within the next few weeks, we'll be able to reach some kind of agreement."

Top Afghan officials and American commanders have suggested the United States will likely retain a military presence in Afghanistan after 2014, when Afghan army and police are due to take over security for the whole country. But the precise size and role of a post-2014 mission have remained unclear.

Panetta told senators a post-2014 mission would likely include counter-terrorism operations against Al-Qaeda and other militants along with providing US air power, intelligence and logistical support for Afghan forces.

At the hearing, Senator Lindsey Graham called for a US force of about 15,000-20,000 troops after 2014.

Afghanistan last month forged strategic agreements with Britain, France and Italy to govern security ties after NATO combat troops exit by the end of 2014.

Nearly 90,000 US troops are now deployed in Afghanistan amid plans for the force to decline to 68,000 by the end of September.

President Barack Obama, who sent a "surge" of reinforcements after entering office in 2009, is pursuing a gradual troop drawdown in Afghanistan, with the bulk of the American force expected to withdraw after Afghan army and police take the lead by the end of 2014.

But analysts have urged the administration to publicly commit to a long-term military presence to prevent the Taliban from seizing back power and to head off a possible civil war with proxies backed by neighboring countries.