Four months after President Reagan's second inauguration, House Democrats yesterday gave their party's supporters the first indication that division and disarray are not their middle names.

By assembling support from every wing of the party to give prompt passage to a budget even Republicans called credible, the Democrats showed themselves a more cohesive and effective force than almost anyone had imagined them to be.

Much of the praise for the achievement was lavished on Rep. William H. Gray III, the black preacher-politician from Philadelphia who was making his debut on the House floor as Budget Committee chairman. Gray was surrounded by admiring colleagues after the 258-to-170 vote, on which only 15 Democrats defected.

But in addition to effective leadership, the turnabout in Democratic fortunes was credited to a shrewd reading of shifts in public opinion, skillful timing by House Speaker Thomas P. (Tip) O'Neill Jr. (D-Mass.), and some unexpected help from Reagan and the Republican opposition.

Whatever the long-term impact, Democrats headed home for the Memorial Day recess believing they had found common ground on a fiscal policy they can defend in their districts -- and perhaps use to embarrass the Republicans as well. That judgment came from party members as liberal as Rep. David R. Obey (D-Wis.) and as conservative as Rep. Marvin Leath (D-Tex.).

"Clearly, House Republicans cannot attack this solid budget with any credibility, and Democrats now have the offensive," said Rep. Tony Coelho (D-Calif.), chairman of the Democratic Congressional Campaign Committee.

The explanation of the Democrats' accomplishment starts with the stark realism of their reaction to the massive Reagan reelection victory last November. "All of us," Obey said, "told Gray to remember that we can't repeal the results of the last election."

That ruled out any resort to higher taxes, the option that 1984 Democratic nominee Walter F. Mondale had argued -- to his own damage -- would be necessary this year. It also meant that House Democrats would have to fashion a package that matched whatever goal in spending reductions Reagan set and the Republican Senate achieved.

"There is a recognition among virtually every one of us," said former Budget Committee chairman James R. Jones (D-Okla.) "that these huge federal deficits . . . are going to be the downfall of the economy . . . .The instincts of political self-preservation dictate that members of Congress are not going to abdicate doing something about them and face the prospects of a recession in 1986 for which they will have to be held responsible."

There was one other factor in public opinion that Democrats gauged more accurately than Republicans -- and certainly than the White House: the increased voter skepticism about the pace of the Pentagon buildup.

In 1981 and 1982, Jones' efforts to fashion a Democratic consensus foundered on the determination of most southern and conservative Democrats to back Reagan's military budget in the face of opposition from the northern liberals. In both those years, the Republicans largely wrote the budget in the Democratic-controlled House.

This year, there was little distance between the Democratic hawks and doves. A conservative such as Leath said, "People like myself, who are very pro-defense, realized this damn thing is getting out of hand. It's dumb to stand up here defending waste, theft and a rotten procurement system."

What proved to be a crucial factor was the early O'Neill-Gray decision to hold off any formal action in the House Budget Committee until the Senate had moved. Their rationale was that Republicans had just won the election and should take responsibility; their real reason, leadership aides confirm, was to force the opposition to take the heat first.

The Senate Republicans obliged. They staged the major confrontation with Reagan and the Pentagon, finally forcing the president to accept a defense budget far below his original request.

"By letting Senate Republicans cut defense first, we're protected from any 'weak on defense' tag," Coelho said.

By withholding their votes, Senate Democrats "stretched Majority Leader Bob Dole to the maximum and even got him into a corner where he had to freeze Social Security benefits . . . ," a House Democratic leadership aide said, "They the Senate Democrats set up the ball, and we spiked it."

The House Democrats were ready to move, once the Senate acted. "I don't ever remember so many meetings" on an issue, O'Neill said yesterday, rejecting suggestions that the floor victory had been easy. "Whenever anyone had a beef and a squawk, we listended to him," O'Neill added.

The Democrats under Jones had used such private negotiating sessions to good effect in 1983 and 1984, but Gray's personality and political position made a critical difference this year. As a center-city congressman himself, Gray had special credibility in getting other liberals to agree to spending cuts.

"It's always easier to go cross-grain in politics," Obey remarked. "A conservative can go to China and a liberal can espouse fiscal discipline."

Conservatives had their own stake in seeing Gray succeed. Leath, who hoped for bigger deficit reductions than the final package provided, said, "It was important to me that Bill Gray come out of this looking good. I want my people to see him as a leader of the Democratic Party -- not Jesse Jackson."

With this range of support, Gray quickly lined up Budget Committee Democrats behind a $56.2 billion reduction package, bigger than Reagan had asked or the Senate had provided. He came close to selling it to the GOP as the best they could get, but that effort was torpedoed by the committee's ranking Republican, Rep. Delbert L. Latta of Ohio.

It was one of several GOP leadership decisions that caused muttering among Republican members. The White House, still reeling from its rough treatment in the Senate, virtually abandoned the House fight and reserved its next maneuvers for the House-Senate conference.

Angry at their leaders and abandoned by the White House, Republicans scattered every which way. A conservative alternative budget lost, 39 to 135, among GOP members; a moderate GOP alternative failed to command Republican support, by 82 to 94. Latta's own leadership package got an embarrassing 101-to-79 majority among Republicans.

"It looks like old Mr. Disarray has moved across the aisle," a Democratic staff aide crowed. And Coelho mailed out freshly minted bumper strips, exploiting the different Senate and House stands on Social Security benefits. It read, "Save Social Security -- Again. Vote Democratic."