Congress last night voted funds to keep the government operating today as negotiators put all but the finishing touches on two bills needed to implement a budget pact that calls for reducing the deficit this year by at least $30.2 billion.

The one-day emergency spending bill approved by Congress funds the government through midnight tonight, and should give lawmakers sufficient time today to enact the two measures that will complete the Nov. 20 deficit-cutting accord with the Reagan administration.

The short-term bill was passed by the House 207 to 178, and a short time later by the Senate on a voice vote, during a rare Sunday session in both houses. President Reagan signed the legislation late last night.

Congressional and White House negotiators cleared the way for today's expected floor votes on the deficit-reduction package when they resolved a relatively minor dispute over an agreement to provide another $8.1 million in funds to the Nicaraguan contras through the end of February.

"We have an agreement, we shook hands on it," said House Majority Whip Tony Coelho (D-Calif.) of the contra aid pact that will permit deliveries of previously authorized military equipment but which is designed to pressure both the rebels and Nicaragua's Marxist Sandinista government to reach a cease-fire in mid-January.

However, substantial numbers of liberal Democrats oppose the contra aid arrangement, and House Democratic leaders estimate they will need as many as 80 Republican votes to overcome defections and pass the deficit-reduction package today.

"We took a pig and dressed it up in a tuxedo, but it's still a pig," said Rep. Robert J. Mrazek (D-N.Y.), reflecting the bitterness of liberal Democrats.

The first bill needed to implement the budget agreement is a $600 billion appropriations measure that funds most government operations through the end of the fiscal year and cuts the deficit by $7.6 billion through reductions in military and domestic spending. The second combines a $9 billion tax increase with additional cuts in permanent federal programs such as Medicare and farm subsidies to yield further cuts in the deficit of about $24 billion.

Congressional negotiators spent much of yesterday scurrying throughout the Capitol to attend a series of private meeting where the few outstanding disagreements in the two bills were being worked out. By nightfall, conferees had agreed on increases in Medicaid, which provides health care to lower-income Americans, and were close to final agreement on cuts in Medicare, the health insurance program for the elderly and disabled.

A dispute over reductions in the Postal Service budget was resolved with an agreement that saves $860 million this year and $1.7 billion over two years, some of it by stretching out lump-sum payments to all federal workers who retire this year and next.

Now, federal workers can receive all their retirement benefits at once upon retirement if they choose. Under the plan, they could receive only 60 percent in the first year of retirement and 40 percent the second. The limitation would be effective only for those retiring in fiscal 1988 and 1989, and congressional aides said they anticipated that it would go into effect the day the deficit package becomes law.

The lump-sum provision accounts for $469 million of the $1.7 billion in two-year Postal Service savings. The rest would come from reductions in future capital expenditures and a requirement that the semiprivate service absorb some health costs of retirees.

The $600 billion spending bill still includes language enacting into law the Fairness Doctrine that requires broadcasters to treat controversial issues evenhandedly. Reagan has threatened to veto the measure over the issue, a position a senior White House aide reiterated last night.

But House Speaker Jim Wright (D-Tex.) said yesterday he "can't imagine" Reagan letting the government "come to a crashing halt" over the issue.

White House and congressional leaders spent much of the day haggling over the final language needed to resolve the contra aid issue, which had been the main stumbling block to a deficit package.

One potentially serious snag developed yesterday as the negotiators disagreed over the timetable for when the Reagan administration would be granted a final congressional vote on additional military aid to the contras should the Central American peace process collapse in January.

Democrats insisted that the tentative agreement reached Saturday called for that vote between July and September, during the height of next year's election campaigns. Republicans were demanding that Reagan have the flexibility to exercise his option at any time to maximize the chance of passage.

The issue was settled by setting the vote for the July to September period, but permitting Reagan to request the additional aid at any time.

Under the complex arrangement agreed to Saturday night:The Nicaraguan contras would get another $8.1 million through February in food, medicine, shelter and clothing and the transportation funding to deliver it. For the first 12 days of 1988, that aid could also be used to ship about 1.5 million pounds in previously authorized military equipment. Such commingling of military aid and new nonlethal aid would not be permitted between Jan. 13 and Jan. 20, during the period when the five Central American presidents will meet to certify whether a cease-fire has been achieved between the contras and the Sandinista government. Following that hiatus, if Reagan finds by the end of January that there is no cease-fire, that the fault lies with the Sandinistas and that the contras have acted in good faith, he can request new military aid from Congress, which must vote on the request on Feb. 3 and Feb. 4. If Congress rejects that new request, the Reagan administration will not be granted another opportunity for a vote on further aid under expedited congressional procedures guaranteeing quick action. However, the contras would still get sufficient aid to leave Nicaragua, and the president could still seek further aid through normal legislative procedures that would not necessarily guarantee a vote. If Congress approves the president's request for new military aid, he would also be guaranteed a second vote under expedited procedures if he wants more aid later in the year.

The complexity of the agreement underscores the intensity of the long battle between the Democratic-controlled Congress and the Reagan White House over funding for the contras. Both sides appeared willing at times to jeopardize a $600 billion bill over a relative pittance that nonetheless carried heavy political and symbolic importance.

For the White House and many Republican lawmakers, the issue was framing an agreement that would not appear to abandon the contras. For Democrats, particularly the House leadership, which had to back off from its previous position of providing no funding, the issue was linking further aid to the peace process.

"The priorities of the administration are right there very blatantly," Coelho said. "They were prepared to shut down the government . . . . The president's priorities in his closing days are contras, contras, contras."

"I don't think there is any victory for either side," said Sen. Ted Stevens (Alaska), a key GOP negotiator on the issue. "It is just a continuation {of aid} until the Guatemala accords play out . . . . It is fraught with danger for {the contras'} future and for Central America."

For Rep. David R. Obey (D-Wis.), a fervent opponent of further aid, the limited attractiveness of the deal is that it might encourage the search for peace and end installment-plan funding of the rebels. "It puts pressure on both the Sandinistas and contras to perform," said Obey. "I don't want to see {the aid} continue dribbing and drabbing. You want one last play, even if it is a Hail Mary for both sides."

On other issues, negotiators reached a compromise over an expansion in Medicaid, which covers health care for low-income Americans. The compromise retained House provisions increasing care for pregnant women and revising rules governing nursing-home care. The cost of the increases in the Medicaid program would be $597 million over three years, according to the Congressional Budget Office, which had estimated that the original Waxman bill would cost an additional $2.3 billion.

Conferees also were close to a deal that would save about $2 billion in Medicare. House Ways and Means Committee Chairman Dan Rostenkowski (D-Ill.) and Senate Finance Committee Chairman Lloyd Bentsen (D-Tex.) defused a conflict over how to increase Medicare reimbursements to Illinois hospitals without depriving those in Texas.

Their method was a common one this time of year: they added $50 million in new funding to the reimbursement program for 1988, keeping rural hospitals even while increasing funds to urban hospitals. The compromise would cost an additional $250 million over three years, money Bentsen said would be made up from reductions in other Medicare programs.

The chairmen also agreed to drop a proposed $10 increase in the deductible paid by Medicare patients. The only remaining disagreement concerned whether to continue linking the amount of Medicare premiums paid by beneficiaries to the cost of the program.

Staff writer Paul Blustein contributed to this report.