President Reagan yesterday signed two long-awaited deficit-reduction bills in a low-key Oval Office ceremony in which he called the bipartisan agreement leading to the legislation "the first step toward placing our country on a reliable and credible budget course."

The measures will reduce the federal deficit by $33.2 billion in fiscal 1988 and $79 billion over the next two years. They exceed the targets of the Nov. 20 deficit-reduction agreement between Congress and the Reagan administration, a compact negotiated in the wake of the October stock-market collapse.

Analysts said some of the savings claimed in the legislation will have minimal effects on the nation's long-run fiscal woes and will only keep the federal deficit from widening significantly. While the measures are expected to please most trading partners, one provision sets stiff trade sanctions against Japan, the first time Congress has initiated such retaliatory steps. {Details, Page F1.}

While Reagan praised the omnibus $598 billion appropriations bill, which continues funding for the Nicaraguan contras, and another measure that includes a $9 billion tax increase and additional spending cuts, he was critical of the process that produced the legislation.

"The normal legislative process should have produced 13 separate appropriations bills," Reagan said. "It did not. Instead, we ran the government on a string of stopgap funding measures, pushing the government right to the brink of defaulting on its commitments to the American people."

The federal government would have shut down temporarily if Reagan had not signed the appropriations bill yesterday. White House chief of staff Howard H. Baker Jr. and Treasury Secretary James A. Baker III urged Reagan to sign the measure despite the reservations of budget director James C. Miller, who objected to Medicare-funding provisions and some other items.

But a White House official said that Miller, after meeting with the two Bakers at 3 p.m., became convinced that the measure was the best the White House was likely to get. They unanimously recommended that he sign the bill.

Reagan called congressional leaders of both parties to thank them. And he invited House Majority Leader Thomas S. Foley (D-Wash.) to the White House to give him one of the four pens he used to sign the two massive bills.

In his bill-signing statement, Reagan cited the funds provided by the appropriations bill "for those fighting for freedom in Nicaragua." He said it is important that U.S. support for the contras not waver "as the Central American peace plan enters a critical period early next year."

Reagan also cited congressional removal from the legislation of a provision reinstating the "Fairness Doctrine," which requires broadcasters to provide balanced comment on controversial issues. The president has previously vetoed a bill continuing this policy and had threatened to veto the measure before him yesterday unless the provision was removed. It was deleted early yesterday as the last change to the package before final passage.

White House officials were jubilant at the result and said Reagan had fared better in negotiations with Congress than at any time since Republicans lost the Senate to the Democrats in the 1986 election.

White House political adviser Frank Donatelli said that signing the bills was "good policy and very good politics for us." White House legislative liaison Will Ball Jr. said the measures provide "real savings" in domestic spending and that the appropriations measure "gives us the stability of two-year planning" on national defense.

The president's signature capped an extraordinary 24 hours even by congressional end-of-session standards. During that time, the House and Senate each debated and passed the two major budget bills, both of them thousands of pages long, influencing the spending of hundreds of billions of dollars and the lives of millions of Americans.

The first, a $17.6 billion package of tax increases, asset sales and cuts in such "entitlement" programs as Medicare, went smoothly. The House accepted it on a 237-to-181 vote Monday night, and the Senate followed just after midnight, passing the measure 61 to 28.

The second bill, however, drew much more opposition because it included a provision providing new nonlethal aid to the Nicaraguan contras. The $598 billion appropriations measure funding most government operations for the rest of the year and reducing the 1988 deficit by $15.6 billion, passed 209 to 208 early yesterday. One hundred and twenty-eight Democrats, a majority of those voting, opposed the package their leaders had crafted.

House Majority Whip Tony Coelho (D-Calif.) said a few lawmakers had been willing to support the aid if their votes were necessary to pass the bill. He pointed out that the complex agreement essentially defers until Feb. 3 a final congressional vote on aid to the contras.

"This is a skirmish; it's not the battle," he said. "What we were trying to do was keep the party together, let people vote their conscience but not lose control of the House so there would be no hard feelings and bitterness and we can come back on Feb. 3 and win."

The Senate approved the bill, 59 to 30, with the contra aid, at 3:30 a.m. yesterday after less than an hour of debate. Senators streaming out of the chamber were ebullient.

Both chambers remained technically in session much of yesterday, although many lawmakers left town on morning flights. Congress adjourned shortly after 4 p.m. until Jan. 25.

Staff writer Tom Kenworthy contributed to this report.