BUDAPEST, Hungary (AP) _ Throngs of Hungarians paid homage Friday to Imre Nagy and others executed for leading the anti-Soviet revolt of 1956, which Hungary's new communist leaders now call the origin of their liberal reforms.

After hours of ceremonies, the remains of the former premier and four associates were interred again, 31 years after they were put to death and buried in unmarked graves on the same spot.

Speeches at the gravesides and at an earlier ceremony in Heroes' Square reflected both sorrow about a national tragedy and the spirit that drove the 11-day revolt ended by Soviet tanks on Nov. 4, 1956.

In the square, the coffins were dispayed on a special platform. A sixth coffin, empty, was set above them to symbolize all the others who died in the uprising and subsequent reprisals.

''If we can muster enough courage, then we can put an end to communist dictatorship,'' said Viktor Orban of the independent youth group, FIDESZ. He demanded the withdrawal of Soviet military forces from Hungary.

''This day marks the change of an era,'' Imre Mecs, who was a student leader in 1956, told the crowd. ''We are burying a regime that was bad from the start, which was rejected by the nation, which was forced upon us and which has proven bankrupt in every regard.''

People joined hands across the square and said, with Mecs: ''We swear that we will never again be slaves 3/8''

At Nagy's grave, Tibor Meray, a journalist who has lived in Paris since 1956, praised him and his associates as the fathers of communist reform.

''From Prague to Warsaw, from Yerevan to the Peking youth ... those movements all have their point of departure with you,'' Meray said at plot 301 in Budapest's Rakoskeresztur cemetery.

''The roots of what is happening in Moscow now go back to you,'' he said. ''The epicenter of the earthquake shaking the Communist world is here in plot 301.''

Official Stalinist versions of history are being re-examined throughout the Soviet bloc, inspired by Mikhail S. Gorbachev's ''glasnost'' policy of openness and the Soviet leader's own criticism of Josef Stalin's excesses.

In Washington, State Department spokeswoman Margaret Tutwiler said the United States sees the honoring of Nagy ''as part of a larger process, that of Hungary coming to grips with the truth of its past ... as the country moves further along the path of freedom toward democracy.''

Those buried with Nagy were his defense minister, Pal Maleter; Minister of State Geza Losonczy; the head of his secretariat, Joszef Szilagyi, and journalist Miklos Gimes, a close associate. All but Szilagyi, who was put to death two months earlier, were executed June 16, 1958.

A year ago, police used clubs to disperse a demonstration on the 30th anniversary. The change began in February, when the Communist Party decided the 1956 revolt began with a popular uprising and was not a counterrevolution as previously held.

On Wednesday, a government statement described Nagy as an ''outstanding statesman.''

Orban, the student leader, mocked the official change of heart.

''We cannot understand the party leaders and statesmen who saw to it that we were taught from books that falsified the revolution, and now rush to touch the coffins as if they were good luck charmsk,'' he said. The crowd applauded.

Janos Kadar, who became party chief when the revolt was crushed, was absent from Friday's ceremony. It was televised live and brought thousands of exiles hoem from abroad, some for the first time since 1956.

Kadar, 77 and said to be ailing, lost the party leadership a year ago and was stripped of his last political posts in May.

Politburo reformer Imre Pozsgay and Premier Miklos Nemeth, two rising political stars, laid a wreath at Heroes' Square and stood in honor guard around Nagy's coffin.

State TV and the official news agency MTI estimated the crowd at 250,000.

U.S. Ambassador Mark Palmer was among foreign dignitaries attending. Absent were Romania, Albania, North Korea and China, whose military assault on student demonstrators recalled 1956 for many Hungarians.

Many with personal memories of the uprising. Younger people wore black armbands bearing the national colors red, white and green, and Nagy's photograph or ''56.''

Bela Kiraly, who commanded the paramilitary national guard under Nagy, said he had vowed not to return from exile in the United States ''until and unless the Hungarian people (could) express their homage to Imre Nagy and his fellow martyrs. Today is that glorious day.''

''The Stalinists forced Bolshevik ideas and the Soviet system upon the Hungarians,'' he declared to the crowd. ''They forged shackles out of ideology and put the Hungarian nation into irons.''

Large Hungarian flags hung in Heroes' Square, with holes cut in the center and filled with black cloth. During the revolt, many rebels cut out the Soviet hammer and sickle that was then part of the national flag.