MOSCOW (AP) _ The Soviet Union apologized Friday for one of the grisliest crimes of the Stalin era: the murder of thousands of imprisoned Polish officers shot during World War II and buried in mass graves in the Katyn Forest.

The confession ended nearly 50 years of official Soviet denial and had been almost a prerequisite for improved Polish-Soviet relations. The Soviet Union previously insisted that Nazi Germany was responsible for the massacre.

Polish and Western historians long have blamed the NKVD, Josef Stalin's secret police, for killing more than 4,000 officers in the Katyn Forest near Smolensk. They were captured by the Soviets at the beginning of World War II.

More than 10,000 other Polish officers were killed in camps elsewhere. Their bodies have never been found, but in its statement Friday the Soviet Union clearly tied together the fates of all 15,000 officers, some of the cream of prewar Polish society.

The admission came 47 years to the day when the Nazis announced the discovery of the Katyn graves. And it came one day after East Germany's new Parliament apologized for the Holocaust and for the deaths of millions of Soviets in World War II.

The statement carried by the official news agency Tass was issued as President Mikhail S. Gorbachev met with Polish President Wojciech Jaruzelski.

Poland had urged the Soviet Union to admit responsibility for the mass slayings, saying such ''blank spots'' in history were a barrier to better Polish-Soviet relations.

Gorbachev gave Jaruzelski copies of the material from Soviet archives pertaining to the Poles imprisoned in the NKVD camps, Tass reported.

In a speech at a dinner Friday night honoring Jaruzelski, Gorbachev referred to the massacre, Tass reported. He said the two leaders talked about ''those historical 'knots' that even many years later cast shadows on our relations. Many of them are undone already.''

''Recently, documents have been discovered which indirectly but convincingly testify that thousands of Polish officers who died in the Smolensk woods half a century ago became victims of (Stalin's secret police chief Lavrenti) Beria and his henchmen,'' Tass quoted Gorbachev as saying.

''The graves of the Polish officers are near Soviet people's graves, who fell from the same evil hand,'' he said. ''It is not easy to speak about this tragedy but we must speak about it for only through the truth there lies the way to genuine renewal and to genuine mutual understanding. ''

The earlier statement said the ''Soviet side, expressing its deep regret in connection with the Katyn tragedy, states that it is one of the most horrifying Stalinist crimes,'' Tass said.

''It's good that criminals admit their crimes,'' Polish Solidarity leader Lech Walesa said in Gdansk. But other problems remain, including war reparations, he said.

The massacre has caused bitterness among Poles for years despite the previous Communist government's loyal statements supporting the Soviet Union.

Jaruzelski is scheduled to visit a memorial at Katyn on Saturday, following pilgrimages of Poles whose relatives and friends died in the massacre.

The officers were captured by the Soviet Union when it invaded eastern Poland at the beginning of World War II, shortly after Hitler sent his soldiers across Poland's western border to start the war.

They were shot in the back of the head and stacked in layers in mass graves. The bodies were found in April 1943 by German soldiers who captured the area during World War II. They were immediately used for propaganda purposes.

Stalin blamed the Nazis for the deaths. Soviet historians recently began questioning that version, but it stood until the Soviet Union admitted responsibility Friday. A U.S. congressional committee in the early 1950s blamed the Soviets.

Under Gorbachev's policy of glasnost, the Soviet Union has brought to light many of the deeds of Stalin and his henchmen, but Katyn was one of the final affairs to be touched by the greater openness.

Records indicate that only 394 of the 15,000 captured Polish prisoners were transferred to the Gryazovetsky prison camp. The rest were turned over to the NKVD, the predecessor of the KGB, in Smolensk; Voroshilovgrad in the Ukraine; and Kalinin northwest of Moscow. All the officers disappeared from NKVD records, Tass said.

Beria and others were executed after Stalin died in 1953.

Historian Natalia Lebedeva, writing in the weekly Moscow News on March 25, said the officers apparently were killed in a single operation as the NKVD evacuated three camps. The Soviets might have considered the Polish officers a threat as potential future leaders of Poland.

Ms. Lebedeva, who used Soviet central archives and Soviet army records, called it a ''well-thought-through and carefully planned operation.''

In Warsaw, Polish relatives of the victims were pleased the truth finally had come out, but expressed regret it took so long.

''I awfully regret that my mother could not live until this day,'' said Wanda Zadrozna, crying as she recalled her father's murder. ''There is a great regret that it took 50 years and the wives of those people didn't live until this day.''

''But whatever happens now, it is good that the truth will be finally written in history,'' she said.