President Clinton yesterday announced the second major shake-up of his administration, replacing White House Chief of Staff Thomas F. "Mack" McLarty with Office of Management and Budget Director Leon E. Panetta and setting new roles for two other senior officials.

In an Oval Office announcement, Clinton said that McLarty will become a senior counselor and that Alice M. Rivlin, the No. 2 official at OMB, will replace Panetta. David R. Gergen, the Republican brought in as counselor to shore up a faltering White House in May 1993, is being shifted to a foreign policy role as senior adviser to both Clinton and Secretary of State Warren Christopher. He is scheduled to depart the administration at the end of the year.

The announcement of McLarty's shift was greeted with relief by many of the president's advisers. A boyhood friend of Clinton's with virtually no Washington experience, McLarty was considered misplaced in the chief of staff job almost from the beginning and was seen as unable to perform one of its principal functions: imposing discipline on the president's operations and schedule, and order on the staff.

He said yesterday that neither he nor Clinton understood the central political and administrative implications of the job when he was selected chief of staff during the transition.

The changes are meant to strengthen the Clinton White House at a critical time in its push for health care reform and other domestic priorities and as it prepares for important midterm congressional elections.

Panetta, in his remarks, said he would make changes in the White House staff in consultation with Clinton. Later, in an interview on ABC's "Nightline," he said he intended to spend the next couple of weeks reviewing "all the operation at the White House" and then make recommendations to Clinton. Clinton, he said, has "no concerns" about the Cabinet, but he reinforced the notion that changes are in store at the White House by saying that the president wanted "a strong organization and good management" there.

McLarty had told friends recently that he realized the chief of staff job was two jobs -- managing up, that is, managing the president, and managing down, to the staff. Under the new arrangement, McLarty has given up managing down. Another adviser to Clinton said, "What the president needs is someone who knows how to manage Congress, knows how to manage the media and knows how to manage Clinton. Mack couldn't do any of the three."

Clinton described the moves not as a demotion for McLarty or a way to ease Gergen out of the White House but as an effort to "add strength and vitality to this White House and our administration" and "an attempt to find the highest and best use for talented people of goodwill who just want to serve their country."

Gergen, who has served in four Republican administrations, was increasingly isolated from domestic policy at the White House because of his moderate views and his Republican credentials. He had sought a greater role in foreign policy formulation and communication during the past several months but national security adviser Anthony Lake and others had resisted.

Officials said that Vice President Gore called Christopher over the weekend, briefed him on the chief of staff shift and said, according to one well-placed official, "but this means we have to find a new role for David."

Gergen will have offices both at the State Department and at the White House, but officials suggested he will be primarily at State. At yesterday's announcement, he said that he anticipated "my tenure in this administration is coming toward a close," but that when asked to take on the foreign policy role, he agreed to do so until the end of the year.

One source familiar with Gergen's thinking said he had always wanted a major foreign policy role "to enhance his resume." Gergen has been talking with potential employers in academia and the news media for weeks. An administration official said of Gergen's shift to foreign policy, "This is intended to increase his lecture fees, and it will." Gergen, a former editor at U.S. News & World Report, made $466,000 lecturing the year before he came to the White House.

Clinton used a sports analogy to describe differences between McLarty and Panetta, whose 30 years in Washington include stints as a congressman and congressional staff member. Recounting the all-America backfield at Army 50 years ago, Clinton said one of the players "was called Mr. Inside and one was called Mr. Outside, reflecting different skills, but they were both all-Americans."

The chief of staff role has become central to the operations of Republican White Houses in the last 50 years, but Democrats, including Clinton, have been averse to the idea of a powerful chief. Clinton was the first Democratic president to name a chief of staff when he took office, but McLarty said in an interview yesterday that neither he nor the president had been satisfied with his operation and began discussing a change several weeks ago.

McLarty said he had envisioned the job as giving Clinton extensive personal counsel and advice. But once in the White House, he found that the political, administrative and public outreach functions of the job prevented much of that. Clinton, he said, wanted him to return to the role of providing advice but not to run the White House.

"He has been and will continue to be my closest and most trusted personal adviser," Clinton said of McLarty. The president praised Panetta's handling of the budget and other issues and said, "No one in Washington has a better understanding of both ends of Pennsylvania Avenue than Leon Panetta."

Despite a daily working relationship with the president over the last year and a half, some advisers said, Panetta does not have a particularly strong or close personal relationship with Clinton. As one outsider familiar with Clinton's style and Panetta's relationship with him said last night, "Can Panetta say no to the president? Can he say no to the First Lady? Can he walk into the Oval Office and say, 'You're really screwing up'? Every president and this one in particular needs someone like that. I am not sure Leon's the one. That may be the fundamental problem with this White House. I am not sure anyone can."

Clinton, McLarty and others described a scenario in which McLarty virtually selected his replacement and then orchestrated it. McLarty described a series of conversations between himself and Clinton that began several weeks ago and culminated with a lunch last Wednesday. McLarty said he had talked with Panetta about the post in early June but it was not until Saturday that Clinton and Panetta, meeting at Camp David, discussed the job.

Gergen was "reassured he was just not being parked at State to get rid of him," one official said, and another source said Clinton had met with Lake on Sunday to receive his blessing and pledge of cooperation. Gergen apparently got what he and others had been pushing for: access to the so-called principals' meetings, where the president's top foreign policy advisers make decisions.

Gergen acknowledged he had little foreign policy experience, and White House and State Department aides described his role primarily as bringing a political and communications expertise to a foreign policy operation that has been heavily criticized. He had already begun some of the functions of his new role as the key coordinator for the president's upcoming overseas trip for the annual G-7 economic summit.

Panetta called the chief of staff job "the toughest in Washington," and few disagree. McLarty became the lightning rod for complaints about Clinton's operation, in much the same way departing chiefs of staff had drawn fire in the last two Republican administrations. Chiefs of staff tend to get fired or shifted to other jobs as a matter of course. President Ronald Reagan fired Donald T. Regan; George Bush fired John H. Sununu and then Samuel K. Skinner.

The Oval Office session to announce the changes was structured to be upbeat, but sounded like a McLarty eulogy. All the officials praised McLarty's decency -- he is a well-liked official in the White House -- and several praised his contributions.

McLarty's role in planning his own departure and replacement is unheard of for presidential chiefs of staff. Most unsuccessful ones leave in a huff, if not a rage. To demonstrate the congeniality of this change, McLarty and Panetta were doing joint television appearances last night, including one on CNN's "Larry King Live."