Lawmakers were preparing to pass a bill banning homosexual "propaganda".
The bill is one of a series of socially conservative measures garnering support in the Kremlin-dominated parliament during President Vladimir Putin's third term.
The gay protesters were far outnumbered by around 200 anti-gay activists who surrounded them, chanting "Russia is not Sodom", singing Orthodox Christian prayers and crossing themselves. They threw rotten eggs at the gay protesters.
After scuffles in which one man was knocked to the ground and kicked by the anti-gay activists, police began detaining the gay protesters and bundling them into waiting buses.
Journalist and Putin critic Masha Gessen said she was among 24 people being taken to police stations. Moscow police said about 20 people were detained.
The State Duma, or lower house of parliament, was expected to pass the bill later in the day, ignoring Western criticism that it curbs basic freedoms and concerns among activists that it is fuelling hate attacks on homosexuals.
The bill would ban the spread of "propaganda of non-traditional sexual relations" among minors and impose heavy fines for violations.
"Traditional sexual relations are relations between a man and a woman, which … are a condition for the preservation and development of the multi-ethnic Russian people," lawmaker Yelena Mizulina told the Duma on Tuesday.
"It is precisely these relations that need special protection by the state," she said.
Critics says the bill – a nationwide version of laws already in place in several cities including Putin's hometown of St Petersburg – would in effect ban all gay rights rallies and they fear it could be used to prosecute anyone voicing support for homosexuals.
"There is already enough pressure and violence against gays and with this law it will only continue and probably get worse," said Viktoria Malyasova (18) standing outside the Duma.
"I may not be gay but I came to stand up for my rights and the rights of other people to love whom they want," she said.
Putin, who has embraced the Russian Orthodox Church as a moral authority and harnessed its influence as a source of political support, has championed socially conservative values since winning a six-year third term in May 2012.
The 60-year-old president denies that Russia discriminates against gays but he has criticised them for failing to increase the country's population, which has declined sharply since the collapse of the Soviet Union in 1991.
Activists say violence against homosexuals has increased since Putin returned to the Kremlin after four years as prime minister and that it is being fuelled by the bill and other aspects of his conservative agenda.
It is unusual for Russian authorities to link crimes with homophobia, but investigators have said anti-gay hate was the motive in the brutal murders of two men in the past month, one in eastern Russia and one in the southern city of Volgograd. – Reuters