WASHINGTON - Congressional Democrats completed work last night on a sprawling, $515.7 billion domestic spending bill that would shave billions from their cherished programs but would challenge President Bush's tough line on domestic spending with billions of dollars for added veterans' care, border security and Southeastern drought relief.

The bill also includes $31 billion for the war in Afghanistan. Democrats expect that billions more will be added for the war in Iraq when the bill reaches the Senate later this week.

Democratic aides say the aim is to win the president's signature by week's end, when Congress hopes to adjourn for the year. To do so, Democrats made scores of concessions, pulling hundreds of millions of dollars from the National Institutes of Health, special education and other programs they had said deserved far more than Bush was willing to spend.

But Democrats did not entirely toe Bush's line. The final bill seemingly meets the president's limit on domestic spending, then adds $11.2 billion in "emergency" spending, much of it long expected.

About $3.7 billion is earmarked for veterans' health care and other veterans' benefits. An additional $7.5 billion in "emergency" funding includes $3 billion that Republicans - and many Democrats - have sought to beef up border security.

Other money would go to drought relief for Southeastern farmers; the Women, Infants and Children federal nutrition program; rebuilding the collapsed Interstate 35 bridge in Minneapolis; low-income heating assistance; wildfire suppression; and assistance to World Trade Center rescue workers suffering from health problems.

By making the veterans' assistance subject to the president's approval, congressional Democrats hope to get around White House demands that the $3.7 billion be offset by cuts elsewhere.

"I think veterans from all over the country will be watching his decision very closely," said Rep. Chet Edwards (D., Texas), who chairs the Appropriations subcommittee in charge of veterans' funding.

A White House spokesman appeared optimistic about the bill's prospects.

To shave $22 billion from the initial spending bills that passed the House, Democratic budget writers had to deliver painful cuts to their priorities and the president's.

The NIH's budget was trimmed $760 million from the amount approved by Congress but vetoed by Bush. Education aid for disadvantaged students lost $280 million.

But other areas would be funded well above Bush's request. Medical research into diseases including Alzheimer's, cancer, Parkinson's and diabetes would get $607 million more than he wanted. The bill is expected to come to a vote in the House tomorrow. The Senate is likely to add as much as $70 billion for the war in Iraq before a vote Thursday.