Congress reached final agreement last night on a $388 billion spending bill funding 13 government departments and dozens of domestic agencies in 2005, after last-minute objections from abortion rights advocates threatened to delay or derail the entire measure.

House passage came on a vote of 344 to 51. Later in the evening, the Senate gave its approval, 65 to 30.

The bill, consisting of more than 1,000 pages and weighing 14 pounds, codifies the stingiest budget for domestic departments since the late 1990s. Although a few favored agencies, such as Amtrak and NASA, were spared cuts, the measure bears evidence of a new austerity in domestic spending, brought about by soaring budget deficits and the rising costs of war and counterterrorism programs.

The abortion battle erupted after Senate negotiators on the huge spending package unexpectedly agreed to a House-backed provision that opponents described as part of a broad strategy by Republican social conservatives to "chip away" at abortion rights. It would bar federal, state or local agencies from forcing doctors, hospitals, insurers, HMOs or other health care entities to provide abortion services or referrals.

"Roe v. Wade is the law of the land, but Republicans are gutting it step by step," said House Minority Leader Nancy Pelosi (D-Calif.). Republicans denied that the legislation would restrict access to abortion and said it is intended only to prevent government agencies from "intimidating" health care entities that did not perform abortions or provide training or referrals.

The abortion language remained in the spending bill, but late yesterday, Senate opponents agreed not to block its consideration after Senate Majority Leader Bill Frist (R-Tenn.) promised to schedule a vote in the near future on a bill drafted by Sen. Barbara Boxer (D-Calif.) to repeal the provision.

Adding to the chaotic finale of the proceedings on the giant bill was a last-minute fracas over another provision, apparently slipped into the bill at the last minute by a House staff aide, that would allow agents designated by the chairman of the House or Senate Appropriations Committee to look at tax returns.

Sen. Dianne Feinstein (D-Calif.) described the provision as a "terrible, egregious abuse of power," and GOP senators joined in denouncing it.

To snuff out what appeared to be an incipient rebellion, Senate Appropriations Committee Chairman Ted Stevens (R-Alaska) took the floor to apologize for the provision and to promise that it would be corrected.

"It's wrong," an angry Stevens shouted at one point, saying it was inserted without his knowledge.

Under an agreement between GOP and Democratic leaders, the Senate later approved language dropping the controversial provision and delayed sending the bill to the president until the House follows suit next week. With spending authority for most federal agencies running out at midnight, Congress also approved stopgap legislation to keep the government running until the spending package becomes law.

The uproar over abortion and tax returns all but overshadowed the underlying spending bill, which Rep. C. W. Bill Young (R-Fla.) described as "a lean and clean package."

The White House had threatened to veto the entire package if domestic spending grew by more than 1 percent, and GOP officials boasted that they had stayed within that margin.

Faced with this ceiling, House and Senate conferees launched marathon negotiations, juggling accounts to take care of White House and congressional priorities.

In a move that underscored the extensive influence of the federal workforce in almost every congressional district, Congress rejected White House objections to a 3.5 percent pay increase for civilian government employees, starting in January.

Despite the spending cap, lawmakers found ways to earmark funds for thousands of highway, bridge, water and research projects in the home states and congressional districts of influential senators and House members.

The Missouri Pork Producers Federation came away with $1 million to develop technology that would improve the environment by converting animal waste into energy. The Big Sandy Airport in Kentucky got $150,000 for "fencing," and $25,000 went for the study of mariachi music in the Clark County, Nev., school district. Airport terminal improvements were approved for Juneau, Alaska, Stevens's home state.

But across much of the rest of the domestic budget, the tight spending ceiling was apparent. Subsidies in the main Small Business Administration loan program were jettisoned, and the administration's request for funds to prepare a nuclear waste repository at Yucca Mountain, Nevada, was slashed by $303 million. The Environmental Protection Agency suffered a cutback of $612 million and, within its accounts, federal aid to rural communities and Indian tribes for water and sewer improvements -- favorite vehicles for congressional earmarks and patronage -- was slashed by $518 million.

To provide more funds for congressional and White House priorities, such as NASA and veterans health programs, negotiators used a combination of accounting gimmicks and a four-fifths of 1 percent tax on all other programs to produce the necessary funds.

Both the White House and GOP leaders said the spending bill is a victory in the battle to get the federal budget back into balance, but Robert Bixby, executive director of the Concord Coalition, a fiscal watchdog group, was skeptical.

"The big money isn't in this part of the budget," he said, noting that domestic discretionary spending makes up barely one-seventh of the total federal budget of $2.3 trillion. The soaring cost of entitlement programs, such as farm subsidies and Medicare, remains largely unaddressed, Bixby said. "They're chasing after the weeds in the lawn while the house is burning down."

Democrats, meanwhile, charged that the package is laden with favors to business and social conservatives, groups that were key to Republican electoral victories on Nov. 2.

Rep. David R. Obey (Wis.), ranking Democrat on the House Appropriations Committee, cited provisions limiting review of timber sales in Alaska, removing wilderness designations in various parts of Georgia, and extending grazing permits without requiring environmental reviews.

Abortion rights forces appeared to have been caught by surprise late last week when negotiators accepted the House-backed provision on abortion services. Abortion rights advocates lacked the votes to challenge it in the House and expected Senate negotiators to object to its inclusion in the final omnibus spending package.

That calculation, however, did not reckon with the fact that Sen. Arlen Specter (R-Pa.), a principal negotiator on health issues, would become a target of antiabortion forces as a result of his recent remarks questioning whether an antiabortion nominee would be confirmed for the Supreme Court by the Senate Judiciary Committee.

Sources said yesterday that although Specter objected to the provision during bargaining on the bill, he was forced to spend much of last week reassuring conservatives that he would push President Bush's nominees for the court, regardless of their position on abortion, if he were chosen chairman of the committee.

Others suggested, however, that the provision's inclusion reflected the strength and increased aggressiveness of GOP social conservatives after the election.

Since the mid-1990s, federal law has provided "conscience protection" for medical students who do not want to undergo training for abortions. The new proposal would expand such protection from medical training facilities to nearly all providers of health care.

While all states would be affected in varying degrees by the proposal, the major impact would fall on the 22 or 23 states that use their own money to provide abortion services to recipients of Medicaid, the federal-state program of health care for low-income Americans. In the future, they would not be able to force health care providers to continue providing abortions or abortion referrals.

According to NARAL Pro-Choice America, 15 states -- others say as many as 17 -- use state funds to cover abortion costs for Medicaid recipients. Another seven states, including Maryland and Virginia, cover costs in some cases, the group said.

The new provision would also make it easier for health care providers to deny Medicaid-funded abortions in rape or incest cases and for federally funded family planning clinics to drop abortion services, according to critics of the provision.