COPENHAGEN - Danish police released four Greenpeace activists on Wednesday who were detained 20 days ago for sneaking into a gala dinner for heads of state to protest against what they deemed failed U.N. climate talks.

Three of them, dressed in evening gown and tuxedo, walked up the red carpet on December 17, duped guards and entered Copenhagen's Christiansborg Palace to unfurl banners saying Politicians Talk, Leaders Act before dignitaries and TV cameras.

The fourth man, who remained outside, was detained later for his part in the protest. Police held the Spanish, Dutch, Norwegian and Swiss activists in custody as a security risk, but said on Wednesday their detention was no longer necessary.

Climate talks in Copenhagen last month secured bare-minimum agreements that fell well short of original goals to reduce carbon emissions and stem global warming, after rich and developing economies failed to paper over differences.

Greenpeace welcomed the activists' release but poured scorn on the Danish police for holding them for three weeks.

The unnecessary imprisonment of these four peaceful activists has effectively been punishment without trial, said Mads Christensen, executive director of Greenpeace Nordic.

The length of their detention without trial is out of all proportion to what was a simple and harmless protest with a legitimate objective, his statement added.

The four have been charged with trespassing, impersonating a police office, falsifying documents and with a further charge that stiffens penalties in cases that occur in the vicinity of Denmark's Queen. They could still face trial and jail sentences.

(Reporting by John Acher; Editing by Jon Boyle)