Islamic guerrillas from Chechnya seized three villages and a town inside the neighboring Russian region of Dagestan today, just hours after a bomb destroyed an apartment building there that housed Russian officers and their families, killing 30 and injuring at least 110.

The developments posed a serious new challenge to the Russian military, which only last week took credit for defeating the Chechen guerrillas in an earlier confrontation. In the latest assault, hundreds of armed Chechens--some reports say as many as 2,000--crossed into Dagestan southwest of the town of Khasavyurt, whose population is made up of a number of ethnic groups, including Chechens. Hundreds of residents of Khasavyurt and surrounding villages were said to be fleeing along country roads to escape the fighting.

Tonight, Russian officials said the Chechens had trapped about 40 Dagestani government troops inside their headquarters in the nearby town of Novolakskoye. They said the troops were running out of ammunition and that Russian army forces had not been able to rescue them.

Leading the guerrilla assault is Shamil Basayev, a leader of the Chechen secession battle with Moscow earlier this decade that left Chechnya virtually autonomous, Russian news reports said. Basayev surprised Russian troops a few weeks ago with a cross-border campaign into Dagestan, seizing several villages and saying his goal was nothing less than creation of an Islamic republic there.

After heavy losses on both sides in that campaign, the Russian military drove Basayev's forces back into Chechnya. Now, he appears to be using similar tactics farther north along the Chechen-Dagestani border. According to Russian officials, Chechen guerrilla units seized the villages of Shushiya, Akhar and Gamiyakh, and a large contingent took Novolakskoye, where the local troops were reported trapped. Late today, intense battles were said to be underway between the guerrillas and Russian troops.

There was no claim of responsibility for the apartment bombing, but Russian Interior Ministry official Vladimir Kolesnikov called the blast and the Chechen incursion "links in the same chain."

The explosion, in the Dagestani town of Buinaksk, collapsed two sections of a five-story apartment building that housed officers of the 136th Brigade and their families, and many women and children were among the victims. Buinaksk is not far from where Russian troops have been attacking two guerrilla-controlled villages.

Today, as rescue workers struggled to pull victims from the collapsed concrete building, a second bomb containing an estimated 220 pounds of TNT was found in a truck parked between a military hospital and another apartment house, the Russian Tass news agency reported. It said the truck was spotted by a sentry, and the bomb was defused.

Last week, the Russian Interior Ministry forces launched attacks on two nearby villages, Karamakhi and Chabanmakhi, but the assault proved difficult, and at week's end the Russian Defense Ministry took over, deploying aircraft and artillery. Today, news services here said Russian planes staged massive raids against the guerrillas, followed by heavy artillery barrages.

The two villages are inhabited by Wahhabite Muslims, who have announced that they are imposing Islamic law on the hamlets. The Wahhabite leaders say they do not recognize the secular government of Dagestan.

CAPTION: Rescuers try to identify a body pulled from the ruins of a Russian officers' residence in the Dagestani town of Buinaksk after a bomb killed 30 people and injured at least 110 there. The building is located not far from where Russian troops have been fighting Chechen guerrillas.