In a dramatic reach across party lines, President Clinton and congressional Republicans came to terms Friday on a plan that would remake the face of government by balancing the budget over five years while cutting taxes for millions of Americans.

At the last moment, a strong economy permitted the two sides to shield Social Security recipients, a change that was gladly embraced by Republicans and that prompted some Democrats to rethink their earlier opposition to the deal."I wanted a balanced budget with balanced values," Clinton said in a subdued appearance before reporters with congressional Democrats by his side. "I believe we got it today."

In contrast to the somber Democrats, Senate Majority Leader Trent Lott and other GOP leaders staged a celebratory campaign-style rally in the Capitol Rotunda, packed with springtime tourists. An ebullient House Speaker Newt Gingrich later told the GOP rank-and-file the deal was "the completion of the `Contract With Amer-ica,' " the conservative manifesto that powered the Republican electoral triumph of 1994.

Sen. Orrin Hatch, R-Utah, reacted with "cautious optimism," noting Washington's long and frequently thwarted struggle toward such a goal.

"He's particularly pleased that this new agreement contains a capital gains tax reduction," said Hatch spokeswoman Heather Barney, who said Hatch credited a Republican Congress with forcing an agreement.

"He strongly believes that the debates in the last two Congresses on a balanced budget amendment were the catalysts that made this happen," Barney said, adding that Hatch has campaigned for that change since he was first elected to the Senate in 1976.

Rep. Merrill Cook, R-Utah, was the first of Utah's congressional delegation to respond to the deal, calling it a step toward "reigning in irresponsible federal spending."

He added that the agreement's tax credit for children will play especially well in Utah, which has the country's youngest population. Cook, whose first term is only four months old, said reaction on the Hill was "euphoric."

"All of us, from freshmen to the most senior representatives, felt like we were part of something historic," Cook said.

While dozens of legislative details remain to be worked out in the weeks ahead, the deal would affect virtually every American - citizen and noncitizen alike.

The plan would carve $115 billion from Medicare, for example, and lead to modest premium increases. At the same time, it would launch a new program of health care for as many as 5 million uninsured children.

Tax cuts would total $135 billion over five years, partially offset by up to $50 billion in increases. Details were left to the tax-writing committees of the House and Senate, but the deal envisions a per-child credit, a cut in the capital gains tax paid by investors, liberalization of the estate tax and breaks for students in higher education. Expanded Individual Retirement Ac-counts are also part of the deal.

Congress will impose no change in the government's cost-of-living index. But the deal assumes the Bureau of Labor Statistics will continue to make changes based on technical factors, a step that will lead to smaller-than-expected inflation increases for Social Security recipients.

Politically, the agreement secured for Republicans two main goals of the revolution they launched after winning power in 1994 - a balanced budget and permanent tax cuts. Lott, R-Miss., said the agreement had been reached "without compromising our principles."

Clinton, too, had campaigned as a supporter of a balanced budget. In addition, the deal permits creation of some of his prized second-term initiatives as well as freeing billions of dollars for domestic programs ranging from the environment to transportation.

The agreement capped weeks of intense negotiations and marked a startling turnabout from the past two years when Clinton and the GOP clashed repeatedly over tax cuts and spending priorities. Those battles resulted in two government shutdowns during the winter of 1995-1996 but no comprehensive agreement. Still, when Clinton was re-elected last fall and the Republicans held control of Congress, the two sides decided to negotiate their differences.

Lott said the turning point in four months of negotiations came when Clinton became per-sonally engaged in the process several days ago. Until then, he said, "everybody was holding back. Nobody was putting real numbers up."

In the end, neither side was completely satisfied.

"The Democrats think the tax cuts are too big, and the Republicans think we're investing too much," Clinton told reporters at a hastily arranged ceremony in Baltimore.

Lott met privately with members of conservative groups who are aligned with the GOP. "He was beaming," said one participant.

The deal was sweetened at the last minute by a dividend from the strong economy, as negotiators learned an estimated $200 billion was available available over the five years.

That led to removal of a provision related to the cost-of-living index, eased the president's proposed cuts in Medicaid and, according to one Democrat, added $26 billion to domestic programs over five years.

After expressing anger at the emerging deal on Thursday, House Democratic Leader Dick Gephardt issued a statement saying he was "encouraged at the movement toward addressing Democratic concerns in regard to additional funding for Medicaid, children's health insurance, welfare-to-work programs and food stamps."

Senate Democratic leader Tom Daschle predicted a majority of the Senate's 45 Democrats would line up behind the plan.

Officials said many of the details remain to be drafted in legislative language, and numerous elementary details were not yet available.

- For example, while officials said deficits would decline annually and vanish in 2002, no year-by-year deficit figures were available.

- Tax cuts will total $135 billion over five years and $250 billion over 10.

- Medicare savings will assure the solvency of the program's trust fund for a decade and lead to a modest premium hike for the home health care program. At the same time, the program will be expanded in the areas of breast cancer, colon cancer and diabetes.

- Spending on the Medicaid program for the poor would be slowed by $15 billion over five years, most of it lower payments to hospitals that care for disproportionately large numbers of poor and uninsured payments.