But lately, Mr. Griveaux’s campaign in Paris had been performing poorly, with polls showing him trailing Ms. Hidalgo and the candidate of the right, Rachida Dati. In the French news media, Mr. Griveaux was criticized for seeming distant and arrogant, even though he tried to capitalize on his status as a young married father of three.

Mr. Macron’s attempt to intercede in his favor ended in failure last month, when he tried to persuade the dissident Republic on the Move candidate Cédric Villani, a prominent mathematician-turned-politician, to leave the mayor’s race. Mr. Villani was kicked out of the party after rebuffing Mr. Macron’s efforts, which was seen as a humiliation for the president.

In France, unlike in the United States, the private lives of politicians and candidates are widely seen as being out of bounds in elections, and the publication of the videos was swiftly and widely condemned. Mr. Macron’s interior minister and close ally Christophe Castaner quickly said that the online publication of the video should “obviously be prosecuted.”

Mr. Pavlensky could face up to two years in prison and be fined up to 60,000 euros if he is convicted of publishing the videos. Under French law, it is illegal to publish or share sexual images or videos online of someone without their consent.

It was not clear how he had obtained the videos, which purport to show a private text conversation that included sexual videos sent from Mr. Griveaux to an unidentified woman. Mr. Pavlensky, who received asylum in France in 2017 after criticizing the Russian state, could not immediately be reached for comment.

A grim-looking Mr. Griveaux responded to the release of the messages in a video statement on Friday morning, saying, “It has gone too far.”

He did not explicitly refer to the videos, but said that for the past year his family had been “subjected to defamatory statements, lies, anonymous attacks, the disclosure of stolen private conversations, as well as death threats.”