Congress last night gave final approval to a long-delayed $9.4 billion spending bill for the rest of this fiscal year as the Senate resolved its last remaining disputes with the House over the measure and sent it to President Reagan for signature.

The bill, which includes funding for scores of federal programs along with new drug-testing rules for federal employes and a moratorium on further construction of the bugging-device ridden U.S. Embassy in Moscow, is expected to be signed by the president, according to White House officials.

Meanwhile, a Democratic-sponsored resolution urging the Reagan administration to delay giving U.S. flag protection to Kuwaiti oil tankers was stymied when Senate Republicans accused the Democrats of "shooting off firecrackers" at the White House and threatened a filibuster.

Although Democratic leaders have conceded Congress cannot block the reflagging, Majority Leader Robert C. Byrd (D-W.Va.) pushed for approval of the nonbinding resolution to assert Congress' opposition to the plan.

Republicans responded with delaying tactics and charges that "this is an effort to embarrass the Reagan administration, pure and simple," as Minority Leader Robert J. Dole (R-Kan.) put it.

Planting himself squarely in the middle, Sen. Mark O. Hatfield (R-Ore.) criticized both the policy and the Democrats' response to it, saying that Congress would invoke the War Powers Resolution if it were really serious about blocking the reflagging.

Instead of doing that, he said, Congress is saying, "We want no accountability; we just want the ability to criticize."

After a brief and inconclusive debate, the resolution -- introduced as an amendment to pending trade legislation -- was set aside for further debate next week, and Democratic leaders filed a cloture petition to cut off the GOP filibuster against the proposal.

Legislation to bar the reflagging is also scheduled for action in the House next week.

In its final business before leaving for a five-day Fourth of July recess, the Senate cleared the way for final approval of the spending bill as it agreed to a House compromise on the Moscow embassy, which has been found to be riddled with Soviet electronic eavesdropping devices.

The compromise would block any more spending on embassy construction -- and prohibit Soviet diplomats from occupying their new embassy in Washington -- until Nov. 1. An earlier Senate proposal would have indefinitely barred further spending on the Moscow embassy except to demolish it.

Pressure to act on the spending bill before the recess was strong because it includes urgently needed funds to resume farm payments and crop loans that have been suspended for two months while Congress dickered over the bill.

The measure also includes a compromise on drug testing for federal employes in "sensitive" jobs, including requirements for uniformity in testing plans and certification standards for those who conduct the tests.

The bill also includes $355 million to finance a new program of emergency aid for the homeless, a major Democratic initiative that was authorized in legislation that Congress approved earlier this week.

Among other funds in the bill were $300 million in economic aid to Central American democracies and $50 million for the Philippines, which both reflect hold-over commitments from last year. Most of the other funds would go to agencies and programs that would otherwise run out of money before the end of the fiscal year, Sept. 30.

The White House indicated Reagan would sign the bill after the House agreed to drop two arms-control provisions, including a ban on all but the smallest nuclear tests and a requirement for resumption of compliance with the unratified SALT II treaty.

In another development, Senate Democratic leaders moved to break a partisan deadlock over campaign-finance changes by introducing a compromise that would minimize use of public funds as an inducement for voluntary agreement to spending limits for Senate campaigns.

Byrd, cosponsoring the bill with Sen. David L. Boren (D-Okla.), said the compromise should meet most Republican objections to taxpayer financing of campaigns but acknowledged that GOP support is still in doubt.

The new plan would allow public financing for a Senate candidate only if the candidate's opponent exceeds spending limits prescribed in the bill. As incentives for agreement to spending limits, the plan would provide reduced radio, television and mailing rates for those who abide by the limits. As a deterrent to excessive spending, it would require candidates who exceed the limits to mention that fact in their advertising and announcements.