For 21 years, since he entered politics as a spokesman for Barry Goldwater, Ronald Reagan has asserted that the United States has no more important mission than defending the cause of freedom around the world.

For 21 years, since President Lyndon B. Johnson set the goal of building a "Great Society" here at home, most Democrats in Congress have worked to find ways the federal government could help states, cities, school systems and individuals achieve their goals.

With yesterday's passage and the promised signing this morning of the Gramm-Rudman-Hollings budget amendment, both Reagan and the Democrats implicitly acknowledged that their old goals would have to yield to a higher priority: cutting budget deficits.

Unless the new process proves to be far less effective in trimming both defense and domestic spending than its backers hope, the dynamics of politics in both parties have been changed fundamentally.

Typically, the politicians involved denied the obvious. Reagan insisted that he still has "no higher priority than maintaining a strong national defense." And such liberal Democrats as Sen. Edward M. Kennedy (D-Mass.) said this was "the only way to protect the important Democratic programs that I care deeply about . . . . " But there was no disguising that both those men and their parties have moved far from their past positions.

In two campaigns for president, Reagan said he could have it all -- the defense buildup, tax cuts and a balanced budget. When Reagan signs the Gramm-Rudman-Hollings legislation to balance the budget by fiscal 1991, he will be agreeing for the first time to reorder his goals.

"There is no other way to read it," said a senior White House official. "It is a major change for Reagan. Signing it is an act of compromise on defense, and it may signify a willingness to compromise on taxes."

Economist Alan Greenspan, who helped draft Reagan's original program, said, "It's fairly clear that Reagan's priorities were unequivocably defense, tax cuts and a balanced budget, in that order. He wished to have all three. But clearly, he didn't trade off defense for taxes, or deficits for defense or taxes for the deficit. It's a very clear priority structure.

"With Gramm-Rudman-Hollings, he does alter his priorities . . . . Implicit in Gramm-Rudman-Hollings is, obviously, a willingness to consider trading defense or even taxes against the deficit," Greenspan added.

Alice Rivlin, former director of the Congressional Budget Office, said the Reagan shift came late but that the "main virtue" of the balanced-budget legislation is that "it forces everyone, including the president, to face up to the agonizing arithmetic" of the deficits.

Many members of Congress and White House officials say the "agonizing arithmetic" will force Reagan to choose between tax increases or still deeper defense cuts. Under the bill, he must reduce the deficit by $50 billion in fiscal 1987, to $144 billion.

Because of areas the president has put off-limits, the "pool" available for cuts is only about $430 billion in domestic programs, according to White House estimates.

For the Democrats, who voted 22 to 22 in the Senate and 118 to 130 in the House for the budget-balancing mechanism, it involved an equal wrench, the prospect of scuttling many Great Society programs.

Two landmarks of New Deal liberalism, the Social Security system and the basic welfare program, Aid to Families with Dependent Children (AFDC), were exempted from cuts. Also protected were Medicare and Medicaid and a few other programs from the Johnson years that target aid to the poor.

But the proposals that were at the center of the Great Society speech Johnson delivered on May 22, 1964, were programs to rebuild the cities and to revitalize the economies of the states, to improve the environment and to bolster education from preschool to college and post-graduate levels.

The bills Johnson pushed through the Great Society Congress in 1965 set a pattern that has mushroomed into almost 300 categorical aid programs, providing grants for housing rehabilitation, for pesticide control, for strengthening skills of teachers of mathematics, science, foreign language and computer learning, and dozens of other purposes.

These programs are the prime targets for reduction in the half of Gramm-Rudman-Hollings cutbacks that must come from the domestic budget. The lobbies that support them were up in arms.

In a typical comment, Mike Edwards of the National Education Association said, "We are obviously opposed to the legislation. It has a disproportionate effect on education." Randy Arndt, a spokesman for the National League of Cities, called it "a gutless way out of the situation . . . . These are not frills being cut."

Such comments raise the basic question of whether the Democrats can embrace the new cuts and maintain their alliances. Most Democrats in Congress have profited from their role as deliverymen for federal aid, the smiling folks who put money in the pockets of local mayors, school boards and social service, arts and environmental agencies.

If the Democrats abandon that role, it is not clear what political part they will choose to play -- or whether their constituents will be eager to continue their long-run control of the House.

Ever since the landslide loss their presidential ticket suffered in 1984, Democrats have been hearing from their pollsters and political consultants that they must shed the label of tax-and-spend liberals. House Democrats, including Speaker Thomas P. (Tip) O'Neill Jr. (D-Mass.), have said repeatedly they will not support a tax increase again until Reagan does.

Some of them said yesterday that Gramm-Rudman-Hollings may force Reagan to accept a tax boost. But there is nothing in the new procedure that requires it. And Reagan was insisting he would not bend on that point.

Still, he has moved a long way just to accept the defense cuts in the procedure. He did so for several reasons, according to officials who have talked with him, and others outside the administration.

One reason, they said, is that with three years left in his term, Reagan has come to view the $200 billion deficits as a potentially serious blot on the record of his presidency. For several years, Reagan ignored those aides -- such as then-director of the budget David A. Stockman -- who warned of peril in big deficits. But last summer, officials say, Reagan began taking a different -- and more urgent -- view of the red ink.

"He said, 'I am going to be judged on it,' " says the senior official. "That's made it real for him."

Another reason was that polls showed deficits had become the overriding concern of American voters. "They showed it had become an issue for Joe Sixpack," said the official.

Yet another explanation is that the defense buildup has been substantial and Reagan may believe after his summit with Soviet leader Mikhail Gorbachev that the pace of military expansion can be slowed.

Another major factor was the unavoidable momentum of the Gramm-Rudman-Hollings bill in Congress. Earlier in the year, both Reagan and Congress struggled fitfully with the deficit. But in September the political dynamics changed and Reagan shifted.

The president mentioned the idea of phasing out deficits over five years to aides in August, one official said. Later, at the urging of chief of staff Donald T. Regan, the president hastily endorsed the Gramm-Rudman-Hollings legislation.

At the time, it was partly a tactical move to get the president over the hurdle of raising the debt ceiling beyond $2 trillion. But Reagan became committed to the budget plan, despite the misgivings of his foreign policy and defense advisers.

"The hysteria over deficits led Congress to move it ahead without daring to look at what it would do to defense," said a senior Pentagon official familiar with Defense Secretary Caspar W. Weinberger's thinking. "The congressional mood was such a panic it was overwhelming -- Reagan didn't have any choice."