Three members of Russia's special forces have been killed and five wounded in a house siege near Khasavyurt in Dagestan, which also left four suspected militants dead.
Militants opened fire with machine-guns and grenades in a bid to escape under cover of darkness, Russia's National Anti-Terrorist Committee (NAK) said.
One of those killed was suspected of organising a bomb attack last month.
Russia has been fighting Islamist militants in Dagestan for years.
It has stepped up security operations in the run-up to the Winter Olympics, due to open on 7 February in the Black Sea city of Sochi, 900km (560 miles) to the west of Khasavyurt.
Security forces have frequently cornered suspected Islamist militants in houses in Dagestan and other parts of the mainly Muslim North Caucasus but Tuesday night's operation appears to have gone badly wrong for the besiegers.
When special forces from the Federal Security Service and interior ministry blocked off the house in the village of Karlanyurt, the occupants put up "fierce armed resistance", the NAK reported on its website.
The special forces managed to stop the suspects escaping but at a cost to themselves of three dead commandos and five wounded, who sustained injuries "of varying gravity".
One of the dead suspects was identified as Marat Idrisov, a militant commander in the Khasavyurt area who is said to have organised a bomb attack on the Russian city of Pyatigorsk on 27 December, in which three people died and three were injured.
Another dead suspect was named as local man Rustam Dagirov, accused of supplying fighters with food and medicine and allowing his home to be used for assembling bombs.
An IED with the explosive power of 50kg (110lb) of TNT was found inside the house along with a magnetic mine, the NAK said.
Since the last war in Chechnya was declared officially over nearly five years ago, Dagestan has become the focus of Islamist militant activity in the North Caucasus.