For two years, the Republican-controlled Senate ran like a well-oiled machine cranking out budgets as divided, demoralized House Democrats gave President Reagan enough votes to win a impressive streak of budget victories.

Now the tables have turned.

With all the lock-step unity that Senate Republicans once displayed to the dismay and envy of their rivals across the Capitol, House Democrats early this spring dashed off a budget of their own and then sat back to watch the fireworks across the way.

In a mirror image of the House Democrats' agonies of 1981 and 1982, when conservatives bolted and helped Republicans pass a budget, GOP moderates in the Senate kicked up their heels last week and voted with the Democrats to scuttle a Republican leadership budget.

As a result, Senate Republican leaders, unable to corral enough votes in their own ranks, must now deal directly with the Senate Democrats in drafting a bipartisan budget resolution that will almost surely please Reagan even less than their previous efforts at compromise.

What happened was less a sudden reversal than the result of a gradual erosion of Reagan's control over Congress, coupled with a widening polarization among Republicans over how to respond to the country's economic troubles.

Last year the Senate Republicans overcame their differences to join in nudging the White House to accept an accommodation that produced, among other things, a substantial tax increase, a slight cut in Reagan's defense buildup and a somewhat looser rein than the president wanted on domestic spending.

But this year taxes became an insurmountable barrier, followed closely by defense.

Conservatives complained that Reagan's tax cuts had been whittled back enough already, and Defense Secretary Caspar W. Weinberger held fast against any military cuts. Reagan also remained dug in on taxes and only slightly less adamant on defense.

In deference to Reagan and the party conservatives, for whom tax increases appear to be a greater evil than deficits, Senate Budget Committee Chairman Pete V. Domenici (R-N.M.) drafted--and Majority Leader Howard H. Baker Jr. (R-Tenn.) endorsed--a budget that preserved Reagan's tax cuts at a cost of budget deficits exceeding $200 billion a year through most of the decade.

This, coupled with the leaders' proposal for only modest restraint in defense spending, strained the patience of the party's small and usually loyal left-wing past the breaking point.

Among the group's leaders, several had just been through grueling reelection campaigns in which they suffered politically from support of controversial Reagan programs, and another is up for reelection in a state that has been especially hard-hit by the recession.

The GOP moderates proposed a budget of their own. Although they failed to pass it, in part because Senate Democrats split at the crucial moment, their success in defeating their leaders' low-tax, high-deficit budget puts them right up there with the party's more vocal right-wing as a force to be reckoned with.

They have also forced a broadening of the party's focus, at least in the Senate, with all the pluses and minuses that such a philosophic expansion entails.

"Basically both parties include a broad political spectrum, Republicans no less than Democrats," said Sen. Slade Gorton (R-Wash.), a freshman moderate who played a key role in trying to fashion a budget compromise that may still form the basis for an agreement. "It may be that what you're seeing now is the norm and the other was the aberration," he added in reference to the collapse of the once-awesome Senate Republican cohesion.

Norm or aberration, this can only compound the problems for Baker, whose style of leadership hinges largely on finding a comfortable middle-ground for his flock and then relying on reason and good will to pull in the stragglers.

The problem for Baker last week was that there were so many stragglers it was hard to find the flock.

With Republicans holding a 54-to-46 majority in the Senate, Baker simply cannot afford to lose many of his own people as long as the Democrats stick together.

He was saved from an even more humiliating defeat by the fact that the Democrats, while virtually united in defeating the Republican leaders' budget, broke apart on the issue of the Republican moderates' alternative.

Had they been more cohesive in support of it, the Democrats could have claimed to have been the dominant force behind passage of a compromise budget resolution. But they, like the Republicans, were split on tax and spending issues and divided on strategy for asserting budget leadership of their own.

In the House, Democrats may still be sharply divided on many issues. But the gains they made in last year's elections--in numbers and in political resolve to stand up to Reagan--put together a solid majority for a Democratic budget for the first time since Reagan took office.

This budget, passed with the help of only four Republicans, includes tax increases large enough to help finance partial restoration of programs cut at Reagan's behest over the last two years, with a little left over to help reduce deficits.

The irony is that the House Democrats passed their budget resolution, including a spending smorgasborg that was too rich for many members' tastes and roughly twice the tax increases that their tax-writers want, in the confident assumption that Senate Republicans would put on the brakes and insist on a relatively tame compromise in conference committee.

If the Senate can't produce a budget, the House will be left with its own plan, which includes a minimum of spending discipline.

And in any case, these fights over a budget resolution are only the first round in the tax and spending battle. Still to come are the specific revenue and appropriations bills for fiscal 1984. If the House budget resolution prevails here, the White House will undoubtedly respond with a "veto strategy." And stronger though they are this year, the Democrats don't have the two-thirds votes needed to override vetoes.

So their ascendancy, too, may last only a moment.