For 15 minutes yesterday, the divergent and often warring factions of the Democratic Party came together to win a battle they never planned to fight.

That is the amount of time House rules allow for a roll-call vote. And at the end of yesterday's showdown over balanced-budget legislation, a Democratic version of the measure had been adopted with only two Democrats opposing it.

With 1 minute and 50 seconds left on their time, the Democrats reached the magic number of 218 votes, a majority of the House. At that moment, shouts of joy erupted from the Democratic side of the aisle, united for once.

But according to many of those involved, it was a closer call than it appeared. Less than 24 hours earlier, key House Democrats had voted in a fashion more typical of their party in recent years. They split 12 to 11 on adoption of a list of federal programs that would be exempt from automatic budget cuts under the Democratic version of the balanced-budget bill.

Even though it was a close vote, the decision by House Democratic members of the conference committee that had reached a deadlock over the Senate-passed budget measure was described as critical in holding together the coalition that prevailed on the House floor yesterday. As a result, Democrats as divergent as Reps. Mickey Leland and Charles W. Stenholm -- Texans from opposite ideological ends of the party -- voted together.

The "short list" of exempt programs for the poor was just long enough to meet the demands of Leland and other members of the Congressional Black Caucus who fear any mandatory deficit reduction would strike hardest at poverty programs.

But it was not so long as to alienate Stenholm, a fiscal conservative from rural Texas and ideological soulmate of one of the chief sponsors of the version of the bill adopted by the Republican-controlled Senate, Sen. Phil Gramm (R-Tex.).

Moreover, the revised Democratic short list made an important addition for many southern conservatives by including veterans' pensions among those programs exempt from automatic budget cuts. This represented a victory for Rep. G.V. (Sonny) Montgomery (D-Miss.), the chairman of the Veterans' Affairs Committee, who had waged a two-week, behind-the-scenes lobbying campaign to put veterans' pensions in the same exempt category as the Senate had put Social Security.

When the votes were tallied yesterday, the only Republican to vote with the Democrats was Rep. John Paul Hammerschmidt (Ark.), the ranking Republican on Montgomery's committee.

While the battle over balanced-budget legislation appeared to be far from over, Democratic leaders were ecstatic at the outcome of yesterday's House showdown.

"There was a tremendous effort" to hold the party together, a House leadership aide said. "They didn't want to lose."

Four years ago, House Democrats did lose, and the memory of that debacle haunted many of them yesterday. It was then that Gramm, at the time a Democratic member of the House, teamed with Rep. Delbert L. Latta (R-Ohio) in pushing through the Gramm-Latta legislation that put in place President Reagan's first-term budget cutting policies. Gramm-Latta was passed because of a large-scale defection from the party line by conservative House Democrats.

In the budget battle of 1985, House leaders feared defections from both wings of the party, from the conservatives who want to balance the budget, even if it means adopting a Republican plan, and from liberals suspicious that even a Democratic plan would strike too hard at the poor.

"They tried to slam-dunk this issue in the hope we couldn't get our act together," Rep. Leon E. Panetta (D-Calif.) said. "Phil Gramm designed it that way because that's the way he operates. He ran into a wall. We learned our lessons from 1981."

The Senate-passed balanced budget legislation is sponsored by Gramm, Sen. Warren B. Rudman (R-N.H.) and Sen. Ernest F. Hollings (D-S.C.). But to House Democrats, the measure has always been the handiwork of Gramm, the turncoat Democrat.

House Speaker Thomas P. (Tip) O'Neill Jr. (D-Mass.), who has never concealed his dislike for Gramm, referred to the Senate measure as the "Rudman bill," apparently preferring not to utter Gramm's name. In the heated House debate yesterday, Gramm-Rudman-Hollings of 1985 was sometimes referred to as Gramm-Latta.

But in addition to fulminating against the Senate bill, Democratic House leaders worked furiously to the last minute to hold their party together. O'Neill made a strong appeal for party unity at a caucus of all Democrats yesterday morning and later met separately with members of the Black Caucus.

At that meeting, O'Neill and other Democratic leaders pledged that the short list of exempt poverty programs would be "nonnegotiable" in any future conference committee meetings with the Senate, according to Leland, chairman of the Black Caucus.

"They would not have had the Black Caucus without that pledge," Leland said. "That is the floor for us."

Earlier, Democratic conservatives had been brought aboard, helped along by the proposed exemption of veterans pensions. The short list, Stenholm said, "went a little further than I would like to see, but I can live with it."

Stenholm said the key factor for him and other conservatives was that the Democratic version promised to begin cutting the budget deficit faster and more deeply than the Republican plan. Four years ago in another budget battle, he and other southerners bolted from the party, Stenholm said, indicating the experience had left a bad taste.

"This time we succeeded in moving our party," he said. "We're going to stay with our party."