When a far-right member of Hungary’s Parliament invited the media three years ago to watch her shred a book of fairy tales that included a gay Cinderella, only one reporter showed up.

But what began as lonely, crank campaign against “homosexual propaganda” by a fringe nationalist legislator, Dora Duro, has snowballed into a national movement led by the government to restrict depictions of gay and transgender people in Hungary.

The campaign has unsettled booksellers, who have been ordered to shrink-wrap works that “popularize homosexuality” to prevent young readers from browsing, and also rattled one of Hungary’s premier cultural institutions.

The director of the Hungarian National Museum was fired this past week for hosting an exhibition of news photographs, a few of which featured men in women’s clothing, and for suggesting that his staff had no legal right to check whether visitors were at least 18 years old.

The exhibition displayed scores of photos awarded prizes by the World Press Photo Foundation in Amsterdam and had been running for weeks before Ms. Duro went to take a look with a friend and noticed a handful of images showing older gay men in the Philippines that were shot on assignment for The New York Times.

Also upset by explanatory texts that she believed were “indoctrinating” young visitors, she wrote a letter to Hungary’s culture minister, Janos Csak, complaining that photos of men wearing high heels and lipstick violated a Hungarian law that bans the display to minors of content deemed to promote homosexuality or gender fluidity.

The minister ordered the museum to bar anyone under 18 from attending the exhibition.

Tamas Revesz, a Hungarian photographer who has organized the annual show for more than 30 years, said he was aghast to arrive at the museum to find signs at the entrance restricting entry to adults “as if this place were a porn shop.”

Ms. Duro, he lamented, “is not disturbed by pictures of the war in Ukraine or of awful ecological disasters but she is disturbed by a man in heels. This is ridiculous.”

The ban is part of a steady shift in Hungary toward using L.G.B.T.Q. issues as a tool to mobilize voters in a country that remains highly conservative in parts, especially away from big cities like Budapest, the capital.

“They all need to score political points, and this is an easy way to win votes with a certain part of the population,” said Huba Szebik, a biology researcher who visited the exhibition and was surprised to find “absolutely nothing disturbing or provocative.”

Zsuzsa Simonyi, a 76-year-old retiree who traveled from western Hungary to attend the exhibition, said she could not understand what all the fuss was about. “No teenager in the 21st century is going to turn gay by looking at these pictures,” she said.

Eight months after Ms. Duro’s shredding stunt in 2020, Parliament, dominated by the Fidesz party of Prime Minister Viktor Orban, passed a “child protection law” that had been amended at the last minute to connect the fight against pedophilia with restrictions on displays of gay and transgender people.

The law made it illegal for minors to be given access to content that “propagates or portrays” any divergence from gender identity at birth, “sex change or homosexuality.”

“I don’t think Orban is homophobic,” said Peter Ungar, a gay member of Parliament for the Green party, “but he wants to avoid losing votes to the far right. If you can’t beat them, join them.”

The 2021 legislation, enacted less than a year before a critical general election, helped Fidesz polish its vote-winning image as a stout defender of Christian values, which had been badly tarnished by a series of sex scandals involving party loyalists.

These included the December 2020 arrest in Brussels of a senior Fidesz lawmaker for violating Covid restrictions by attending an all-male orgy and then trying to flee down a drainpipe. A prominent Fidesz mayor had earlier been caught on video taking part in a mixed-sex orgy on a yacht.

The new law lay dormant for more than a year, but, with elections looming for municipal governments and the European Parliament, Mr. Orban’s government has activated its provisions. In March, the authorities issued a decree banning “the display or popularization of homosexuality” within 200 yards of schools and churches. In other locations, all books intended for underage readers with homosexual content must be shrink-wrapped in plastic.

Undercover inspectors from the consumer protection agency started visiting bookshops and levying fines for violations. This month, the authorities expanded the crackdown to the national museum, firing its director, Laszlo Simon, on Monday after he mocked the adults-only entry requirement for the photo exhibition.

“It is a big campaign and has had an enormously chilling effect,” said Eszter Mihaly, a researcher in Budapest for Amnesty International.

Norbert Szabo, the manager of a private bookshop in central Budapest, said he was “very confused” over which books needed to be wrapped and relied on publishers to tell him which texts, if left unsealed, might violate the law.

To be safe, he keeps some volumes behind the counter, including the latest book by the gay Israeli writer Yuval Harari, “Unstoppable Us, Volume Two: Why the World Isn’t Fair.”

The Hungarian-language edition of the book, aimed at young adults, carries a note from the publisher warning that the text needs to be sealed in plastic “because some pages touch on historical facts relating to homosexuality.”

“We all thought the 2021 law was just a pre-election move, but this spring they started fining booksellers,” said Krisztian Nyary, a prominent writer and a director at Lira, a big chain of bookshops. He said Lira had been fined about $34,000 for selling “Heartstopper,” a graphic novel for young adults that features a love affair between two schoolboys. “This was a big shock.”

It was, he added, “a signal to the whole industry: Watch out.”

Also fined was Hungary biggest bookseller, Libri, which is owned by close allies of Mr. Orban.

The same warning was given to the museum director, Mr. Simon. A longtime Fidesz party loyalist who used to be a member of Parliament, he voted for the 2021 “child protection” law and, at the museum, swiftly implemented the culture minister’s demand to restrict entry to the photo exhibition.

But he torpedoed his career by mocking the adults-only rule as counterproductive given that it generated a huge buzz around the photos and increased attendance. In a message on Facebook, he sarcastically thanked Ms. Duro for creating the ruckus, posting a photograph of crowds waiting to get in.

“The museum of the nation is alive and well. Thank you, dear Representative Duro,” he wrote. In a statement after his dismissal, he denied that he had “sabotaged the child protection law. I acknowledge the decision, but I cannot accept it.”

Ms. Duro, who is now deputy speaker of Parliament, said in an interview that her intention was never to get the museum director fired but added that he deserved his fate for undermining the struggle to protect Hungarian youth.

With her radical party, Our Homeland Movement, surging ahead of liberal groups in recent opinion polls, she described her book-shredding as “a successful operation” that had helped to awaken the country to a “better understanding of the dangers our children face.”

Hannah Reyes Morales, who took the photographs at the center of the museum furor while on assignment for The New York Times and won a World Press Photo award, said her pictures of a Manila community called Golden Gays “are not dangerous or harmful” but portrayed “warm, kind and loving human beings.”

She said she was “saddened that their story is being kept in a shadow, echoing much of the oppression that the Golden Gays have had to live through over the years.”

Nicole Taylor, a spokeswoman for The Times, said: “Hannah’s images represent a powerful and poignant photographic essay that shines a light on an oppressed community and helps increase understanding of the lives of others. We condemn any move to politicize or censor important journalistic work.”

Mr. Revesz, the organizer of the exhibition, bemoaned that Budapest, the capital of a country famed for its culture and a member of the European Union for nearly two decades, could fall into a censorious fever reminiscent of Hungary’s Communist past.

“I’ve been organizing these events for more than three decades and have never experienced anything like this,” he said.

Hungary, he said, was the first Eastern European country to host a World Press Photo exhibition and it had only run into government interference once before — in 1977, when Gyorgy Azcel, a member of the Politburo responsible for culture, declared an image of the Soviet dissident writer Aleksander Solzhenitsyn “undesirable.”

The portrait was taken down and moved to the women’s washroom.

Barnabas Heincz contributed reporting.