Senate and House Republican leaders yesterday closed ranks behind a plan to balance the federal budget within six years, and House Speaker Thomas P. (Tip) O'Neill Jr. (D-Mass.) said Democrats, as well, may embrace "something of that nature."

In a groundswell of support, Senate Majority Leader Robert J. Dole (R-Kan.) predicted it will pass the Senate, possibly today, and House Democratic leaders indicated after day-long huddles on the issue that it might be acceptable with some fine-tuning.

President Reagan said he was "in agreement" with goals of the plan. While he stopped short of an outright endorsement, White House officials and Dole said they expect Reagan to do so today.

The plan would mandate a reduction of roughly $36 billion a year in the deficit, which is now estimated at $180 billion. By 1991, the budget would be balanced. The plan is in the form of an amendment to legislation raising the government's debt ceiling from $1.8 trillion to $2 trillion. The government's cash balances are expected to run out by Monday, and the debt-limit extension must be passed by then so the government can continue borrowing to pay its bills.

However, House Democratic leaders indicated they may press for a temporary extension lasting 15 days so they can negotiate a compromise with the Senate on the deficit-reduction plan.

While Congress earlier this year approved spending reductions of $55.5 billion for this fiscal year, deficits remain the dominant issue on Capitol Hill, and many lawmakers are reluctant to raise the debt ceiling to $2 trillion without further action to curb deficits. That reluctance gave impetus to the balanced-budget proposal, which originated with Sens. Phil Gramm (R-Tex.), Warren B. Rudman (R-N.H.) and Ernest F. Hollings (D-S.C.).

One House Democrat said the proposal roared through Congress like a "firestorm." Republicans rushed to endorse it yesterday and Democrats scrambled to respond.

"The main issue in America today is not trade, is not taxes, is not foreign affairs. The main issue is the deficit," O'Neill said in designating a high-level task force to explore possible counterproposals, which were also under study by Senate Democrats.

However, instead of proposing an alternative, the Democratic task force welcomed the Senate plan as "an excellent opening to deal with the terrible deficits and mounting debt that have continued to haunt our country's economic future," in the words of its chairman, Majority Whip Thomas S. Foley (D-Wash.).

Foley called the plan "the first crack in the wall of those who have ardently defended the administration's program" and said he was asked by the Democratic leadership to say it would "deal with the Senate deficit reduction proposal and any proposed modifications . . . in an expeditious fashion."

Some Democrats, while acknowledging Republicans may have scored politically in seizing the initiative on the issue, said they thought it could work to Democrats' advantage in increasing pressure for defense spending reductions and forcing Reagan to consider tax increases.

Under the Gramm-Rudman-Hollings proposal, the president and Congress would be required to keep their budgets within fixed limits aimed at eliminating the deficit by fiscal 1991, when it would otherwise still be about $100 billion under current estimates.

If joint calculations of administration and congressional budget experts project that the limits will be exceeded by more than 7 percent next year and 5 percent thereafter, the president would be required to make across-the-board cuts to bring spending within the limits.

The cuts would occur equally from discretionary spending, including defense, and from annual adjustments for benefit entitlement programs except for Social Security, which would be exempt.

Congress could avoid the automatic cutbacks by approving an alternative deficit reduction plan, including spending cuts, tax increases or a combination of the two.

Waivers would be permitted in time of war or recession. Otherwise, Congress would have to act to relax the provisions.

Despite the surge of support for the proposal, some qualms were also expressed.

The administration was pushing for changes to protect defense spending from big cutbacks. Several senators voiced misgivings about exclusion of Social Security from automatic cutback provisions, with some expressing fear that its exclusion would increase the burden of cutbacks for benefit programs aimed at the poor.

Democrats were quick to blame Republicans for creating the deficit crisis in the first place.

An alternative under study by Senate Democrats, developed by ranking Budget Committee Democrat Lawton Chiles (Fla.) and endorsed by Minority Leader Robert C. Byrd (D-W.Va.), would produce a balanced budget by fiscal 1990, a year earlier than the Gramm-Rudman-Hollings proposal.

This would be achieved in roughly equal amounts from tax increases, domestic spending cuts and reductions in the military buildup. Tax increases would be in two forms: a minimum tax on corporations and wealthy individuals and a reduction in inflation adjustments for income tax rates.

Whether congressional action on the legislation would blunt the national drive to amend the Constitution to require a balanced budget is not clear. While a majority of state legislatures have approved resolutions calling for a constitutional convention to draft such an amendment, proponents are still several states short of the 34 required to force such action. The legislation under consideration in Congress is not a constitutional amendment.