WARSAW — It was meant to foster unity and celebrate the sacrifices of past generations in the creation of the modern Polish nation. But after days of wrangling and controversy, the country’s Independence Day celebration on Sunday ended up highlighting Poland’s deep divisions.

President Andrzej Duda and senior members of the government walked at the front of a state-sponsored procession through the streets of Warsaw behind a huge red-and-white Polish flag with an inscription “For you, Poland.”

And Mr. Duda told the crowd that “this march should unite all Poles,” adding, “Let this march be for everyone.”

But hundreds of yards behind the officials from the governing Law and Justice Party were far-right activists known for promoting racist, homophobic and supremacist slogans.