WARSAW — Growing up in a small city in southern Poland, part of a religious family and conservative community, Maciej Gosniowski was told again and again that something was wrong with him.

“It would be better if I changed myself,” he recalled teachers telling him. “It would be better if I behaved more like a boy. It would make my life easier.”

Mr. Gosniowski was beaten by other students who used homophobic slurs he did not yet understand. He does not want other young people to suffer as he did, so he welcomed the decision by the mayor of Warsaw to introduce a declaration last month aimed at promoting tolerance.

But the backlash to the declaration has left him shaken.

Poland’s governing party, Law and Justice, has seized on the declaration and the issue of gay rights in its campaigning for European Union elections in May and for national elections this fall.