At the heart of the rapid rise of the nationalist right, with its view of immigrants as a direct threat to the essence of France, there appears to lie a growing feeling among many French people that they are no longer at home in their own country.

That feeling, a vague but potent malaise, has many elements. They include a sense of dispossession, of neighborhoods transformed in dress and habits by the arrival of mainly Muslim immigrants from North Africa, and of lost identity in a fast-changing world. The National Rally, whose anti-immigrant position lies at the core of its fast-growing popularity, has benefited from all this.

“No French citizen would tolerate living in a house without doors or windows,” Jordan Bardella, the smooth-talking 28-year-old symbol of the National Rally’s advance to the brink of power, told France 3 TV this past week. “Well, it’s the same thing with a country.”

In other words, nations need effective borders that can be sealed tight.

This message, echoed by rising nationalist parties across Europe, and a central theme of Donald J. Trump’s presidential campaign in the United States, has proved potent. In France, it propelled Marine Le Pen’s National Rally to victory over President Emmanuel Macron’s party in voting for the European Parliament this month.

So rattled was Mr. Macron by the defeat that he threw open the country’s political future with a risky bet. He called for legislative elections, the first round of which is June 30. France may have a nationalist far-right government with Mr. Bardella as prime minister before the Olympic Games begin in Paris on July 26.