WARSAW, Poland (AP) _ Polish authorities said Monday they were investigating the cause of a methane gas leak that set off a powerful explosion in an underground coal mine, killing 18 miners in Poland's worst mining accident in three years.

The body of the 18th miner killed in Sunday's blast in the southwestern city of Walbrzych was brought to the surface Monday morning and ''the rescue operation was ended,'' said the official Polish news agency PAP.

Six of the eight injured miners were released from a Mining Ministry hospital in the city, PAP said. It added that two miners remained hospitalized, but their lives were not in danger.

PAP said safety teams were working to repair damage caused by the blast, which was touched off by leaking methane gas in a shaft of the mine 660 feet beneath the surface where 26 miners were doing maintenance work on machinery.

Polish leader Gen. Wojciech Jaruzelski sent a message of condolence to the victims' families saying the ''painful event'' had ''deeply moved Polish society,'' PAP reported.

The accident was the worst at a Polish mine since November 1982, when 18 miners died in an underground explosion at a colliery in the southern town of Bytom. It raised to 106 the number of miners killed underground in Poland this year.

Mining officials said a special commission from the Mining Ministry was investigating the accident but withheld comment on the possible causes of the blast or the methane gas leak.

''I can't say anything about the reasons for the explosion,'' Jozef Janik, a spokesman for the ministry in the southern city of Katowice, said in a telephone interview.

Officials at the mine, contacted by telephone, refused to comment and said all information was being released to PAP.

Residents of Walbrzych, a city of 138,000 people located in the heart of coal-rich Silesia where mining is a way of life, were shocked by the accident, said a reporter at the local newspaper, Trybuna Walbrzyska, in a telephone interview.

Red-and-white Polish national flags flew at half-staff outside mines and on city buildings next to black-and-green miners' flags, said the reporter, who spoke on condition of anonymity. Black mourning ribbons decorated the flags.

''You can imaginge what the mood might be,'' the reporter said. ''It is sad, solemn. The people feel very sorry.''

PAP said all cultural and entertainment events in the city were canceled, and Monday was declared a day of mourning in Walbrzych province.

Walbrzych is located 220 miles southwest of Warsaw, about 15 miles from the Czechoslovak border.

Poland is the world's fourth-largest producer of coal behind the United States, the Soviet Union and China.