Congress voted last night to bail out the government for two more days as House Democratic leaders moved to break a logjam on a full-year spending bill for most government agencies by agreeing to shelve controversial water projects that had prompted presidential veto threats.

The Democrats' move, which came after inconclusive efforts by Senate Republicans to negotiate a compromise with the White House, appeared aimed at prodding President Reagan to come to agreement on other major sticking points, including aid to anti-government insurgents in Nicaragua.

"Rather than provoke a confrontation in the highly charged, election-year atmosphere, we decided to take the first step and drop the water projects as an act of good faith," House Majority Leader James C. Wright Jr. (D-Tex.) said. "Now we're in a position to ask him [Reagan] to be reasonable about the war in Nicaragua."

Under discussion among some key lawmakers was a Nicaragua compromise, similar to one worked out on the MX missile. It would bar further U.S. aid to the "contra" guerrillas until Congress can vote again on the issue next year, possibly in February or March.

A House-Senate conference on the nearly $500 billion overall spending bill was deadlocked all day over Nicaragua and other defense-related issues and recessed last night in hopes that the emergency two-day extension would allow time to work out details of the long-term settlement.

If all goes as planned, House and Senate leaders hope to be able to adjourn the 98th Congress by Thursday, already a week beyond the target date for adjournment, and avoid the specter of a "lame-duck" session after the Nov. 6 elections.

There had been increasing talk during the day that such a session might be required if the spending bill could not be resolved in time for members to go home and campaign for reelection.

The extension, approved speedily by voice vote in both houses, would last through midnight Thursday and, in the meantime, prevent a repeat of last week's partial shutdown of the government.

In its worst such snarl in memory, Congress had approved three emergency extensions of funding authority since the new, 1985 fiscal year dawned Oct. 1 without passage of most appropriations bills for the year.

Reagan shut down nonessential government operations for half a day last Thursday, even as Congress was approving one of the interim extensions. The latest extension expired at 12:01 a.m. today, and the government had been prepared for another shutdown unless Congress acted.

The Democrats' maneuver on the water projects takes an issue away from the White House and puts the Senate Republicans in a bind.

The White House had the upper hand politically in any veto fight as long as it could blame Democrats for padding the measure with "budget-busting" pork-barrel projects.

Now the "pork" issue is in the hands of Senate Republicans, some of whom have been as eager for water projects as the Democrats, and the White House would be forced to fight out a veto with Democrats on such less popular issues as aid to Nicaragua.

In other action as the 98th Congress struggled to finish its work: House-Senate conferees meeting on the massive immigration revision bill broke up indefinitely when House conferees voted against a $1 billion ceiling on annual reimbursements to states for the cost of legalizing millions of illegal aliens under the measure.

President Reagan has threatened to veto the bill if it does not include such a cap. Earlier, the group approved a compromise on an anti-discrimination provision. The bill's chief Senate sponsor, Alan K. Simpson (R-Wyo.), refused to declare it dead, and there remained a possibility last night that the House vote against the cap might be reconsidered. The House approved and sent to President Reagan a bill to create a youth conservation corps patterned after the Civilian Conservation Corps of the 1930s. The measure, which the administration has opposed, would create an American Conservation Corps to provide 37,000 summer and year-round jobs on federal, state, local and Indian lands at an estimated cost of $225 million through fiscal 1987. The House overwhelmingly approved and sent to the president a bill extending the Head Start program for two years and establishing community-based before- and after-school programs for "latchkey" children. The bill also establishes a scholarship program for outstanding high school graduates who intend to become teachers. The Senate, dealing with the other major stumbling block to adjournment, spent several hours on legislation to increase the debt ceiling from $1.57 trillion to $1.82 trillion but gave up for the night after bogging down on amendments involving taxation on self-financed sale of homes and farms.

Even before Congress headed into another evening session on its money problems, the Rev. Richard G. Halverson, the Senate chaplain, said a prayer. "Father in heaven," he said, "we are here under duress, but we imposed this situation on ourselves."

Senate Majority Leader Howard H. Baker Jr. (R-Tenn.) appeared to agree, saying that nothing short of a "religious miracle" could prevent need for further emergency funding legislation.

Compounding the House and Senate conferees' problems was a letter from Office of Management and Budget Director David A. Stockman, written Friday and circulated yesterday, that made previously implicit veto threats explicit.

The letter referred to conferees' plans to include money to start water projects that could ultimately cost about $6 billion, as well as a House proposal, opposed by the Senate, to include a broader authorization for $18 billion in new projects over the next two decades.

"As we have stated on numerous occasions over the past four years, the administration believes that fundamental reform in the financing of the construction and operation of federal water development projects must precede initiating new construction starts," Stockman said. "If we were to permit the approximately $6 billion worth of new projects in the tentative conference agreement to go forward, any future effort at reform would be virtually meaningless. We must accordingly take strong exception to the inclusion of any appropriations to initiate construction starts."

Objecting as well to inclusion of the larger authorization measure, Stockman said inclusion of any of the water project proposals "would cause the president's senior advisers to recommend that he disapprove the bill."

By last night, the conferees had whittled down the money for new starts, but Senate Republican aides said the administration was still balking at compromise offers from Republicans and Democrats.

The Democratic leaders' offer extended to the authorization and appropriations proposals, including port-dredging projects to accommodate super-sized coal carriers in Baltimore and Hampton Roads. Some lawmakers said a few projects may still be considered, especially if necessary to win Senate Republican acquiescence.

The water projects and defense issues appeared linked to the extent that House conferees, along with some senators, were reluctant to go out on a limb on such controversial issues as aid to the Nicaraguan "contras" without assurance that Reagan would not veto the bill because of domestic spending.

When they recessed, conferees were at an impasse over restrictions on testing of anti-satellite weapons, funding of Reagan's "Star Wars" defense system in space, deployment of nuclear-tipped, sea-launched cruise missiles and a proposed ban on combat troops in Central America and aid to insurgents n Nicaragua.

The Democratic-controlled House would ban further aid to the contras, while the Republican-run Senate would allow it to continue..

House conferees wanted to take the contested issues back to the House for a vote, but senators balked. "There's no education in the second kick of a mule," observed Sen. Ted Stevens (R-Alaska)