BRUSSELS — The European Union put some of its deepest divisions on display on Friday in its last scheduled summit meeting before the summer break.

The splits among the 27 member states were significant on issues of culture, sex education, rule of law and foreign policy, in particular toward neighboring Russia.

Hungary and its new law on sex education, which critics say targets the L.G.B.T. community, proved the most emotional topic, with Prime Minister Xavier Bettel of Luxembourg describing what it has meant to him to be gay and Prime Minister Mark Rutte of the Netherlands asking openly whether Hungary would be better off leaving the European Union if it disagreed with the bloc’s laws and values.

But policies toward Russia and its president, Vladimir V. Putin, were also hotly debated early Friday morning, at a long working dinner that did not finish until 2 a.m. A joint effort by Chancellor Angela Merkel of Germany and President Emmanuel Macron of France to adjust a policy paper to call for a summit meeting between the European Union and Russia, after President Biden met Mr. Putin in Geneva, was repelled angrily by Central European leaders and others, including Sweden and the Netherlands, as hasty and ill-advised.

Krisjanis Karins, Latvia’s prime minister, said: “The Kremlin does not understand free concessions as a sign of strength.”

Even countries normally sympathetic to Franco-German initiatives criticized the effort as ill-prepared and initiated late, with no prior consultation. Ms. Merkel and Mr. Macron argued that the European Union should have its own channels to Moscow and not depend on the Americans. In general, the Germans have always believed in keeping lines of dialogue open with Russia almost no matter how it behaves, while Mr. Macron has been trying to reset France’s relations with Moscow, with little success.

In this case, the prime mover was Germany, with French support.

Early Friday, a visibly tired Ms. Merkel said in her uninflected fashion that “it was not possible to agree that we would meet immediately at leaders’ level, but what is important to me is that the dialogue format is retained and that we’re working on it.” She added: “Personally, I would have liked to have taken a bolder step here.” But she said that in “a very detailed and also not an easy discussion,” the leaders did agree on the conditions that would be required for such a summit meeting.

Mr. Macron said it was important for the European Union, in its own interests, to speak to Russia with a “unified voice” and a “structured agenda,” instead of only reacting to events.

At the same time, the leaders agreed unanimously to approve harsh new sanctions on key sectors of the Belarusian economy, as a response to the anti-democratic crackdown by the government of President Aleksandr G. Lukashenko and the state hijacking of a passenger plane to arrest a young dissident journalist, Roman Protasevich. They also rolled over existing sanctions against Russia for its annexation of Crimea and support for rebels in eastern Ukraine.

Hungary and its new law, which bans the depiction or promotion of homosexuality to those under 18 years of age, an addition to legislation targeting pedophiles, was the most wrenching topic. Prime Minister Viktor Orban defended the legislation, which was signed into law on Wednesday, before the summit meeting began, as an effort to protect children and argued that it would have no effect on the rights of adults.

But many leaders saw it as an effort to stigmatize the L.G.B.T. community and connect it to pedophilia and thus a violation of the European Union treaties protecting individual rights. The president of the European Commission, Ursula von der Leyen, called the law “a shame” and said that it “clearly discriminates against people based on their sexual orientation” and violates “the fundamental values of the European Union: human dignity, equality and respect for human rights.”

Others were more scathing to Mr. Orban’s face, according to diplomats who were there, wondering what had happened to a man who came to power as a defender of democracy and opponent of totalitarianism.

Mr. Orban defended the legislation, diplomats said, arguing it was designed to protect children and maintain matters of sexual orientation for parents and not schools. He said that the law was misunderstood by its critics and not aimed at the gay community. “I am being attacked from all sides,” Mr. Orban said at one point, although he did have some support from Poland and Slovenia.

Before the meeting, Mr. Orban said: “I was a freedom fighter in the Communist regime. Homosexuality was punished and I fought for their freedom and their rights. I am defending the rights of homosexual guys. But this law is not about them, it’s about the rights of the kids and the parents.”

Mr. Bettel was having none of it. “I used to have respect for Mr. Orban,” he said before the summit, adding: “Europe is not just about laws and subsidies, it’s also about rights and obligations.”

Mr. Bettel gave an intensely personal account of realizing that he was gay and how hard it was to tell his parents. “The most difficult thing for me was to accept myself when I realized that I was in love with a person of my sex, was how to say to my parents, how to say to my family,” he said, emphasizing that young people who are gay are prone to suicide if they fail to embrace who they are.

Mr. Bettel, who sometimes travels to official meetings with his husband after their marriage six years ago, said that conflating homosexuality with pedophilia or pornography was wrong, as was stigmatizing people, adding that he did not see himself as a threat to anyone.

“I didn’t get up one morning after having seen some advertising and just become gay,” Mr. Bettel said. “That’s not how life works. It’s in me, I didn’t choose it. And to accept oneself is hard enough, so to be stigmatized too, that’s too much.”

Mr. Rutte described Mr. Bettel’s intervention afterward, saying: “Everybody had tears in their eyes.”

Charles Michel, the president of the European Council, defended the debate as vital to the functioning of the bloc and its democracy. But the new law is just the latest episode in Mr. Orban’s long-running conflict with the European Union. His government has been accused of building what he himself calls an “illiberal democracy,” of manipulating the news media and the courts, misusing E.U. funds, toying with anti-Semitism and mistreating minorities and migrants. His party, Fidesz, left the main center-right political grouping in the European Parliament, the European People’s Party, just before it was to be expelled.

The Irish Taoiseach, Micheal Martin, said: “There was absolutely no doubt leaving that meeting that Hungary was left in no doubt that a line had been crossed, and without question it would have implications in terms of future decisions around funding.”

Mr. Rutte openly told Mr. Orban that if Hungary did not want to be part of the European community of values, it should leave the bloc.

Judit Varga, Hungary’s justice minister, called Mr. Rutte’s comments “no more than another episode from the political blackmailing series. Hungary doesn’t want to leave the E.U. On the contrary, we want to save it from hypocrites,” she wrote on Twitter.

The commission is now expected to bring Hungary before the European Court of Justice, its highest court, for breaching the treaties. In the past, Hungary has accepted the rulings of the court, but like most courts, it does not provide particularly quick decisions.

Monika Pronczuk contributed reporting.