WASHINGTON - Congressional negotiators reached agreement Thursday on a compromise spending bill to avert a weekend federal shutdown. They also worked toward a deal renewing the payroll tax cut and unemployment benefits for another year but prepared a shorter version as a fallback in case talks fell short.

Senate Majority Leader Harry Reid (D., Nev.) told reporters he was still optimistic that bipartisan talks on yearlong extensions of the Social Security payroll tax cut and unemployment coverage would succeed. But as a "Plan B," he said, they were also working on a two-month extension, which would also prevent cuts in Medicare reimbursements for doctors for that period.

Reid's remarks put a slight damper on a day on which, for the first time, Democratic and Republican leaders expressed optimism at prospects for swift compromise on their payroll tax standoff and a spending battle that had threatened to shutter federal agencies starting Saturday.

A deal on a $1 trillion spending bill was reached after Republicans agreed to drop language that would have blocked President Obama's liberalized rules on people who visit and send money to relatives in Cuba. But a GOP provision will stay in the bill thwarting an Obama administration rule on energy-efficiency standards that critics argued would make it hard for people to buy inexpensive incandescent lightbulbs.

The House is expected to approve the spending measure Friday, and the Senate could follow suit, possibly the same day.

Bargainers were considering the two-month version of the payroll tax cut and unemployment-benefits bill because they haven't agreed on how a yearlong extension would be paid for, said a Democratic aide who spoke on condition of anonymity to discuss the private talks. The two-month bill would cost $40 billion, according to the aide, and would let lawmakers revisit the measure after the holiday season.

Donald Stewart, spokesman for Senate Minority Leader Mitch McConnell (R., Ky.), said talks aimed at agreeing to a yearlong bill would continue.

"We're 12 hours into this debate, they just started talking," he said. "I wouldn't hit the panic button."

Still another year-end bill, setting new rules for the handling of terror suspects in U.S. custody, won final congressional approval and headed to Obama's desk for his signature.

On the payroll tax cut, the president said: "Right now, Congress needs to make sure that 160 million working Americans don't see their taxes go up on Jan. 1." He was referring to the tax-cut extension at the core of the jobs program he outlined in a speech three months ago.

House Speaker John A. Boehner of Ohio, the most powerful Republican in an era of divided government, agreed. "We can extend payroll tax relief for American workers, help create new jobs, and keep the government running. And frankly, we can do it in a bipartisan way," he said.

'Some movement'

The previous day's bristling rhetoric and partisan jabs all but vanished. Republicans agreed to consider changes to a $1 trillion spending bill compromise that they and at least one Democrat said were wrapped up days ago. The White House said it wanted adjustments.

There were separate negotiations on legislation to extend the payroll tax cut and unemployment benefits. Democrats abandoned their demand for a surtax on million-dollar incomes that they wanted to include in the measure, removing a provision that Republicans strongly opposed.

At a news conference, Boehner minimized the concession, noting that Democrats lacked the votes to impose the surtax a year ago when they commanded 60 votes in the Senate. Even so, he said, "there was some movement yesterday from the White House and Democrat leaders" toward a compromise.

Boehner also left open the possibility of a compromise on another issue - a House-passed provision that all but requires construction of the proposed Keystone XL oil pipeline from Canada to Texas.

Construction "will put 20,000 people to work immediately And there are about 115,000 other jobs directly related to it," he said. Yet he did not to say construction of the project was a nonnegotiable condition as talks on the payroll tax-cut bill proceeded.

Senate defense bill

Obama has threatened to veto the House-passed bill, in part citing the requirement for the pipeline. The project has been studied for more than three years, but the president recently announced he would put off a decision until after the 2012 elections.

The president also wants to leave in place a system that provides aid for up to 99 weeks for the long-term unemployed. The House-passed measure reduces the total by 20 weeks, a step that the administration says would cut off 3.3 million individuals and that Democrats are hoping to soften if not reverse.

Also part of the negotiations was an attempt to head off a threatened 27 percent cut in payments to doctors who treat Medicare patients, an item added in the House to appeal to conservatives unhappy at extending the payroll tax cuts.

The separate defense bill covered military personnel, weapons systems, the wars in Afghanistan and Iraq and more at a cost of $662 billion, $27 billion below Obama's request. The Senate approved it, 86-13.

The main controversy involved a provision to require military custody for foreign terrorist suspects linked to al-Qaeda or its affiliates and involved in plotting or attacking the United States. Under a change made to gain Obama's backing, the legislation would permit the FBI to arrest and interrogate foreign terror suspects, as is now the case.