The ruling comes as human rights activists in Russia and elsewhere who criticize the law as discriminatory have called for a boycott of the Winter Olympics set to open in Sochi in February, the Russian Legal Information Agency reported.
The decision by the Constitutional Court dismissed a complaint by gay rights campaigner Nikolai Alexeyev, who said the St. Petersburg city council acted unconstitutionally when it passed an ordinance banning the promotion of homosexuality among minors.
Fines up to $150 can be imposed on an individual violating the law and up to $15,000 for organizations.
Alexeyev had been fined under the legislation for holding up a poster bearing the words: "Homosexuality is not a perversion, unlike grass hockey or ice ballet."
Alexeyev had argued the law was based on prejudice and allowed discrimination against people based on their sexual orientation.
In ruling the law was constitutional, the judges said the constitution obliged the state to protect motherhood, childhood and family.
The court said the law was not discriminatory because it applied equally to gay and heterosexual people.
The law does not prevent adults from making their own sexual choices, the Kremlin maintains. Russian President Vladimir Putin has vowed no one at the Winter Games will be discriminated against "on any basis whatsoever."
S. Korea sees trouble ahead: a low birthrate
Sex club scandal shakes Japanese government