WASHINGTON — Senate leaders agreed on compromise legislation Friday night to extend Social Security payroll tax cuts and jobless benefits for two months while requiring President Obama to accept Republican demands for a speedy decision on the fate of an oil pipeline that promises thousands of jobs.

A vote is expected today on the measure, the last in a highly contentious year of divided government. House passage is also required before the legislation can reach Obama’s desk.

In a written statement, White House communications director Dan Pfeiffer indicated Obama would sign the measure, saying it had met his test of “preventing a tax increase on 160 million hard-working Americans” and avoiding damage to the economy recovery.

The statement made no mention of the pipeline. One senior administration official said the president would almost certainly refuse to grant a permit. The official was not authorized to speak publicly.

Racing to adjourn for the year, lawmakers moved quickly to clear separate spending legislation avoiding a partial government shutdown threatened for midnight.

The developments came a few hours after the White House publicly backed away from Obama’s threat to veto any bill that linked the payroll tax cut extension with a Republican demand for a speedy decision on the 1,700-mile Keystone XL oil pipeline proposed from Canada to Texas.

Obama recently announced he was postponing a decision until after the 2012 elections on the much-studied proposal. Environmentalists oppose the project, but several unions support it, and the legislation puts the president in the uncomfortable position of having to choose between customary political allies.

Republican senators leaving a private meeting put the price of the two-month package at between $30 billion and $40 billion and said the cost would be covered by raising fees on new mortgages backed by Fannie Mae and Freddie Mac.

The legislation also would provide a 60-day reprieve from a scheduled 27 percent cut in the fees paid to doctors who treat Medicare patients.

Several officials said it would require a decision within 60 days on the pipeline, with the president required to authorize construction unless he determined that it would not be in the national interest.

Officials said that in private talks, the two sides had hoped to reach agreement on the full one-year extension of payroll tax cuts and jobless benefits that Obama had made the centerpiece of the jobs program he submitted to Congress last fall.

Those efforts failed when the two sides could not agree on enough offsetting cuts to make sure the deficit wouldn’t rise.

In a statement, Senate Majority Leader Harry Reid blamed Republicans, saying they had wanted to “cut Medicare benefits for seniors” and Democrats refused. GOP officials disputed him.

“We’ll be back discussing the same issues in a couple of months, but from our point of view, we think the keystone pipeline is a very important job-creating measure in the private sector that doesn’t cost the government a penny,” said Sen. Mitch McConnell of Kentucky, the Republican leader.

The State Department, in an analysis released last summer, said the project would create up to 6,000 jobs during construction, while developer TransCanada put the total at 20,000 in direct employment.