Former congressman Allard K. Lowenstein, 51, a Pied Piper to three generations of student activists and the organizer of the "Dump Johnson" movement in 1968, was fatally shot in his New York law office this afternoon by a man police identified as Dennis Sweeney, 37, a former Lowenstein protege.

Doctors at New York's St. Clare's Hospital operated on Lowenstein for more than five hours. Police said he died shortly after 11 p.m.

Lowenstein was sitting in his office in Rockefeller Center when Sweeney walked in and shook hands with him, according to a police officer.

A few moments later a telephone installer working nearby said he heard "screams and then pops -- three or four."

After the shooting, the gunman walked out of Lowenstein's office, put his 9mm semiautomatic pistol on a secretary's desk, lit a cigarette and sat down to await police, according to witnesses. Police charged Sweeney with second-degree murder and possession of a deadly weapon.

"It was unbelievable," the telephone installer said. "He didn't even tremble. He could have been long gone. Everybody panicked after the shooting. People ran all over the place. Somebody took the gun with a handkerchief and put it away."

Sweeney, once a dashing student leader at Stanford University whom Lowenstein recruited for civil rights work in Mississippi in 1964, has a history of mental disorders and has been hospitalized briefly at least once, according to friends in the San Francisco area.

A team of nine or 10 surgeons operated on Lowenstein for five hours in a desperate but vain attempt to save his life tonight. The lead surgeon, Dr. William Mitty, said after Lowenstein died, "his heart just failed to continue to function."

Earlier doctors had described Lowenstein's initial survival of the five shots as miraculous. During the operation they removed his left lung and repaired three separate wounds to his heart. The first prognoses were rather hopeful, but by late tonight Mitty said Lowenstein probably had suffered brain damage when he lost all of his blood in heavy internal bleeding, and that his heart was not working as it should after the prolonged surgery. Soon after Mitty gave that assessment, the former congressman died.

Bruce Payne, a professor at Duke University and a friend of Lowenstein and Sweeney, said tonight that Lowenstein expressed deep concern in December about Sweeney's mental condition.

Lowenstein said then that he had seen Sweeney last fall in Philadelphia. Payne said Lowenstein told "a very alarming story about Dennis being completely off his rocker." Sweeney told Lowenstein he was having all of his teeth removed because the Central Intelligence Agency had planted a transmitter in them, Payne recalled.

"I know you're after me," Sweeney told Lowenstein at that meeting, Payne recalled Lowenstein saying.

New York police officer Robert Burke said Sweeney told police tonight he felt that Lowenstein was "putting pressure on his family, causing his father to have a fatal heart attack." Sweeney's father, Gerald, a printer in Portland, Ore., died last month.

Lowenstein had been an activists' activist for 30 years, from his student days at the University of North Carolina through this year's Kennedy campaign, in which he had been working hard. Tonight, Sen. Edward M. Kennedy cut short his campaigning in Chicago to fly here.

Lowenstein served in the House for one term (1969-71) as a Democrat representing a Long Island constituency, but was redistricted out of office. Half a dozen subsequent efforts to be reelected from other districts or elected to the Senate failed.

As an undergraduate, as a law student at Yale, as an officer of the National Student Association, as a dean at Stanford and a teacher at North Carolina State, Yale and the City University of New York, and throughout his political career, Lowenstein had a way of attracting loyal student followers. He was said to know thousands of people all over the country. Dozens of friends and relatives gathered in an emotional scene at St. Clare's Hospital here tonight.

In a statement issued from the White House, President Carter called Lowenstein "a passionate fighter for a more humane, more democratic world" and said he deplored the act of violence that cut short "a life devoted to reason and justice."

Lowenstein's greatest political triumph came in 1968 when the Dump Johnson movement he organized helped Sen. Eugene McCarthy (D-Minn.) push Lyndon B. Johnson from the White House. After failing to persuade either Sens. Robert F. Kennedy or George McGovern to challenge Johnson that year, Lowenstein threw the considerable weight of his movement behind McCarthy's candidacy, initially regarded as a hopeless quest.

After Johnson withdrew in March 1968 from the race, Lowenstein told a group of his followers: "We did it without a major name, money or the mass media. We showed that the system is not so resistant to change, but that it is badly corroded."

It was a characteristic emotion, Lowenstein never abandoned working "within the system," a position that at various times brought him into conflict with some of his porteges, reportedly including Sweeney. In 1965, Sweeney accused Lowenstein of selling out the Mississippi civil rights movement by failing to support the increasingly militant Student Non-Violent Coordinating Committee (SNCC).

In 1971 Lowenstein tried another "dump" movement to unseat President Nixon by registering millions of voters under 25. But this effort flopped.

A political whirling dervish, Lowenstein could never go for long without a new cause, either a campaign of his own or a crusade for others. During his term in the House he was extremely active, pushing reform of that body's procedures and traveling the world.

Later he won a place on Nixon's "enemies list," became a critic of the conventional view that Robert Kennedy was killed by Sirhan Sirhan acting alone, served in the Carter administration as an envoy to the U.N. Human Rights Commission and worked for California Gov. Edmund G. (Jerry) Brown Jr. and, most recently, for Edward M. Kennedy. In 1978 he lost a bid for the Democratic nomination to run for Congress from New York's Silk Stocking District, and this year, friends said, he was considering another try for elective office.

Lowenstein's personal manner was gentle but intense. He evoked strong emotions -- not always affectionate ones -- in those who knew him best. Some of his closest friends from undergraduate days at the University of North Carolina, for example, fell out with him years ago. Others remained fiercely loyal.

Lowenstein was an avid wrestler who worked out regularly at New York's Yale Club. A friend, Hamilton Richardson, the former tennis star, said tonight that Lowenstein's good physical condition may have made his initial survival possible.

In 1966 Lowenstein married Jennifer Lyman. They had three children and were later divorced.

Sweeney became one of Lowenstein's followers in 1964 at Stanford, where Lowenstein was a controversial associate dean of men. Jack Newfield, the New York writer, remembered Sweeney and Lowenstein in Mississippi in the summer of 1964, where Sweeney was arrested several times and injured in a bombing incident. Lowenstein was a father figure to Sweeney then, Newfield said tonight.

In 1973, a group of friends in the San Francisco area raised money to send Sweeney to a mental hospital in the East when they learned he was having serious problems, one of the friends said tonight. At the time, this source said, Sweeney believed he was picking up messages from outer space, and frequently spoke an incomprehensible language. He stayed at the mental hospital a week, then fled to France, this friend recalled.

Sweeney, who is divorced, lives in New London, Conn., where he apparently has worked as a carpenter. Friends described him tonight as a burnt-out case from the 1960s activist movement.

In New London, his landlady described Sweeney as "kind of weird. He thinks somebody's after him and things like that."