The suspects are from Central Asian countries and have been active since November, Russian officials add.
There is no evidence they are connected with Akbarzhon Jalilov, a Kyrgyzstan-born man suspected of bombing St Petersburg's metro.
Monday's attack killed 14 people and injured almost 50.
Those detained had been recruiting other Central Asian immigrants in St Petersburg "to carry out terrorist crimes" and to join "illegal armed groups", including IS, Russia's state investigative committee said in a statement.
Extremist Islamist literature was found during a search of their living quarters, it added. No other details have been given.
Meanwhile, investigations continue about the alleged metro attacker, his motives and whether he had any links to radical movements. No group has said it was behind the attack.
There is speculation that the attack was retribution for Russia's air raids on Islamist militants in Syria.
The head of Russia's investigative committee Alexander Bastrykin asked officials to look into any potential "links" between the alleged attacker and IS, AFP news agency reported.
IS has recruited many Islamist militants from Central Asian republics and the North Caucasus.
The investigative committee on its website (in Russian) has named most victims of the explosion, which happened on Monday afternoon after the train had left Sennaya Ploshchad station.
Six people have been detained in St Petersburg suspected of recruiting for so-called Islamic State (IS) and aiding terrorist activity, investigators say.