The House passed its annual Pentagon policy bill this summer, but the Senate’s version has been pending for weeks, bogged down in a dispute over the number of Republican amendments that would be allowed to come to a vote. As Republican and Democratic leaders battled over procedure, the House and Senate Armed Services Committees negotiated behind the scenes on a compromise bill.

The measure is the first change to law governing sexual assault in the military in years, stemming from the furor that has erupted over the rising numbers of sexual assaults in the military; there were 3,553 sexual assault complaints reported in the first three quarters of this fiscal year, a nearly 50 percent increase over the same period a year earlier.

The problem has drawn particular scrutiny in this Congress by the seven women on the Senate Armed Services Committee, who were divided on the best approach to contain the problem. “This agreement represents a huge win for justice in America’s armed forces,” said a joint statement from Senator Claire McCaskill, Democrat of Missouri, and Senator Kelly Ayotte, a Republican from New Hampshire, who have both offered measures to combat sexual assault.

Ms. Gillibrand intends to move forward with her legislation to remove commanders as a stand-alone bill; Senator Harry Reid of Nevada, the majority leader, has assured her a vote.

House and Senate negotiators turned back Mr. Obama’s renewed push to close the military prison at Guantánamo Bay, extending a prohibition on the transfer of prisoners to the United States and forbidding the construction of facilities to house them. But they did loosen restrictions on the transfer of Guantánamo prisoners to other countries.

Senator Carl Levin of Michigan, chairman of the Senate Armed Services Committee, said the change should ensure that about half the detainees still at the military prison will be transferred. Half will remain.

There was no guarantee that the remaining few days of this session will be smooth for the Pentagon bill, pending nominations or other matters that must be dealt with. Without a military policy bill, the Pentagon will no longer be able to offer combat pay to troops, re-enlistment bonuses or impact aid to local schools and governments near military bases, a cudgel that Armed Services leaders intended to use to force consideration of their measure.