After years of struggling to make political capital from the federal budget deficits of the Reagan era, Democrats in Congress found themselves ill-prepared and badly divided when a Republican deficit-reduction plan swept through the Senate this week.

"We muffed a very serious issue," said Sen. Gary Hart (Colo.), one of just 20 Democrats who voted against a bill that seeks to eliminate the deficit by fiscal 1991 by prescribing annual deficit-reduction targets and triggering automatic across-the-board budget cuts if they are not met.

The divisions in the party were clear from the vote: A majority of Democrats -- 27 -- voted with the Republican majority. Of 10 Democratic senators facing reelection next year, six voted with the GOP.

"It's not as if we were blindsided," Hart said. "The [Senate] Democrats have been defensive and reactive since [President] Reagan came to power."

Hart's assessment was widely shared by members of both parties. At least for the short term, Senate Republicans believe that by springing a clever political trap, they have recaptured the initiative on an issue many had come to fear might imperil their party's election prospects next year.

"For the first time in quite a while, the Republicans have been able to go on the offensive," Kirk O'Donnell, counsel to House Speaker Thomas P. (Tip) O'Neill Jr. (D-Mass), said. "Until now, they'd been on the defensive this fall on all the national agenda issues, from trade to deficits to South Africa."

Democrats, meantime, have been left to wage a rear-guard action in the House to modify some components of the plan, and to hope that Senate Republicans have unwittingly created a procedural straitjacket that will wind up pinching their own budget priorities at least as badly as those of Democrats.

That hope helped produce the unlikely configuration of votes among Democratic senators on Wednesday. The 27 Democrats who sided with the GOP majority on a 75-to-24 vote for the deficit-elimination plan were a broad array of liberals and conservatives.

"This is going to force the president to look at [cuts in] defense and to look at [raising] revenues," said Sen. Carl Levin (D-Mich.), a proponent of the view that the bill will backfire on the Republicans. "The bill is an admission of the failure of Reaganomics," added Rep. Tony Coelho (D-Calif.), chairman of the Democratic Congressional Campaign Committee.

But Hart and other Democrats were more sour. "It seems like we got caught in a moment of panic," former Democratic National Committee chairman John White said. "It was not one of our finest hours."

Hart and Sen. Daniel Patrick Moynihan (D-N.Y.), both of whom opposed the bill, saw it as the "final act" of a carefully planned, long-term GOP strategy to use runaway budget deficits as a pretext for reducing the scope of the government.

The debate on the bill produced an intriguing political subplot that saw Hart and Sen. Edward M. Kennedy (Mass.), the two presumptive front-runners for the 1988 Democratic presidential nomination, undergo something of a role reveral. Each chose a position designed to shore himself up with those elements of the party with whom he is weakest.

"Hart decided to become Sen. Compassion, and Kennedy Mr. Fiscal Responsibility," one Democratic activist quipped.

The bill was a matter of heated debate in both senators' offices, according to reports from various Democratic staff workers. In the end, Hart went onto the floor to talk about a "morally unacceptable" bill that would increase the rate of hunger and deprivation in the nation, while Kennedy said that the congressional budget process was in "chaos," that it needs to be fixed.

For Kennedy, the vote was of a piece with the vote he cast earlier this year in favor of the line-item veto, another procedural remedy designed to get at the budget deficits by increasing the power of the presidency.

"We have always believed in a strong presidency," said Paul Tully, director of Kennedy's political action committee, the Fund for a Democratic Majority. "And if our vote also shows we're serious about the deficit, well, we're not complaining."

Others see Kennedy's effort to moderate his big-spender image as a strategy that will undermine the very essense of his political appeal: his constancy of values.

Kennedy's vote put him, on this issue, to the right even of Rep. Jack Kemp (R-N.Y.), who yesterday told reporters that he worried that the bill would force unacceptably "Draconian cuts" in social programs and defense if a recession occurred.

Just as Kennedy is eager to recast his image, so are broad elements of his party. The GOP capitalized on this new Democratic hunger to be the party of fiscal responsibility by attaching the deficit-reduction measure to a bill raising the U.S. debt ceiling, one of the most difficult votes for a senator to explain to constituents.

What surprised some observers is not that Republicans used the debt ceiling vehicle -- they had been telegraphing their intention to do so for months -- but that the Democrats seemed so ill-prepared with a response.

"Most of the Democrats who voted for this bill don't like it . . . and I'm a little surprised they didn't figure out a better way to get around it," said Norman Ornstein, a congressional scholar with the American Enterprise Institute.

If there is any good news for the Democrats on the deficit-elimination vote, it's of the left-handed variety.

Last year, their party's presidential nominee spent the fall campaign trying to make an issue of the GOP deficits. He was conspicuously unsuccessful. The deficits are not an easy issue for Democrats, and if they had it taken away from them this week, they may not have lost much.