President Reagan denounced a $23 billion deficit-reduction bill yesterday as an attempt by congressional "big spenders" to "blackmail" him, then signed the measure as Republican cosponsors of the legislation looked on uneasily in the White House Rose Garden.

"To those who say we must weaken America's defense, they're nuts," Reagan said. "To those who say we must raise the tax burden on the American people, they're nuts."

The unusual seven-minute ceremony ended with Reagan responding to a reporter's shouted question about whether the "big spenders" included any of the Republican congressional leaders in attendance.

"No," the president said. "If you want to show your pleasure with what I said, give them a hand. They're on our side."

Administration officials clustered in the Rose Garden dutifully applauded the GOP congressional leaders and Sen. Ernest F. Hollings (D-S.C.), even though they had supported the bill that Reagan called an invitation to more spending.

The president signed the measure over the objections of Defense Secretary Caspar W. Weinberger, who warned that it could result in severe defense budget cutbacks.

Standing in the White House colonnade, out of range of television cameras, was White House chief of staff Howard H. Baker Jr., who a senior official said had prevailed over Weinberger "with a lot of help" in intense discussions before Reagan's decision to sign the measure.

"It was Cap against the world, which means it was essentially an even fight," said an official, who observed that Weinberger prevailed routinely in controversies about defense budget issues.

This time, officials said, Baker and his deputy, Kenneth M. Duberstein, out-maneuvered Weinberger by bringing in congressional leaders and Treasury Secretary James A. Baker III to tell the president that a veto would harm Republicans.

"A veto would have exploded our credibility on the deficit, and we would have been overridden," an administration official said. "Republican candidates would have denounced us. What good would that have done the president?"

Republican sources said Reagan had nonetheless intended to veto the measure but changed his mind after hearing the arguments of the two Bakers, Duberstein and six GOP congressional leaders at a meeting Thursday. One of these sources said Weinberger's absence was also helpful, adding, "This will teach Cap to go to the Persian Gulf."

Reagan's decision was a significant victory for Howard Baker, a former Senate majority leader who early this year succeeded Donald T. Regan as chief of staff.

In March, the president rejected Baker's advice to sign an $87.5 billion highway and mass transit bill, and his veto was overridden. Subsequently, Reagan also rebuffed Baker's suggestion to invoke the War Powers Resolution in the Persian Gulf.

Some Republican members of Congress have complained privately that Baker, after these defeats, was unwilling to make recommendations that he knows Reagan will oppose.

Reagan made no attempt yesterday to disguise his objections to the bill he was signing, even though earlier in the day he told a World Bank audience that the legislation was "a signal that America is not backing down from its responsibilities."

In his Rose Garden remarks, Reagan said Congress is trying to force him "to pay for its uncontrolled domestic spending by endangering our national security or by raising your taxes or both."

The president vowed that he would do neither and said he was signing only because the bill contained a provision raising the federal debt limit to $2.8 trillion.

The measure will correct a constitutional defect in the Gramm-Rudman-Hollings legislation invalidated by the courts, restoring an automatic "trigger" requiring that $23 billion be cut from the budget, half of it from military spending, if the president and Congress cannot agree on a plan to reduce the deficit.

Asked after the ceremony where the $23 billion in cuts would come from, Senate Majority Leader Robert J. Dole (R-Kan.) responded, "Beats me." But Dole also said sale of federal assets and various user fees might account for some of the required reduction.

Reagan has resisted suggestions for a "budget summit" to devise a compromise that would avoid the automatic budget cuts, but Democratic leaders predicted yesterday, as Sen. Carl Levin (D-Mich.) put it, that Reagan "will finally end up at the negotiating table because . . . the public wants us to work out our differences."

But Reagan's Rose Garden rhetoric also produced angry reactions on Capitol Hill.

"I think clearly the signal that came forth is a signal of confrontation nd not of cooperation," House Budget Committee Chairman William H. Gray III (D-Pa.) said.

"I certainly hope that the harsh rhetoric of today is not what we can expect over the next six weeks as we try to come up with $23 billion worth of deficit reduction so we can reduce the growing sea of red ink that this administration's policies have brought to this country. What I heard today was the president saying nuts to compromise, nuts to negotiation, nuts to the deficit," Gray said.

Reagan was alluding to the reply of Army Gen. Anthony McAuliffe, who was asked to surrender U.S. forces in Bastogne during the Battle of the Bulge in World War II. His one-word reply to the German commander on Dec. 20, 1944, was, "Nuts."Staff writer Tom Kenworthy contributed to this report.