President Obama held up the success of a post-Communist Poland as a model for aspiring democracies on Wednesday as he vowed to defend a region long trampled by foreign forces from any future threats.

“Here we see the strength of free nations that stand united,” Obama told thousands of Poles gathered to hear the American president on the 25th anniversary of the country's first Western-style elections.

“This land was invaded and conquered, carved up and occupied,” Obama said. “Those days are over. Every nation must be free to chart its own course, forge its own partnerships, choose its own allies.”

Under overcast skies in a public square on the Vistula River, Obama extended the troubled history of Eastern Europe to the current turmoil in Ukraine, where a fight for control of the eastern part of the country bears echoes of the East-West tug of the Cold War era.

He called Ukrainians the “heirs to Solidarity” -- the Polish movement that led to the ouster of the Communist government.

“Our free nations cannot be complacent in pursuit of the vision we share -- a Europe that is whole and free and at peace,” he said. “We have to stand with those who seek freedom.”

Obama spoke near the clock tower of the Royal Castle, a symbol of Poland’s long struggle for statehood. Bombed by the Germans and left in shambles by the Communists for more than 25 years, it was reconstructed and opened to the public in 1994.

Thousands gathered in front of the castle for the keynote of several celebrations marking the anniversary. Polish President Branislaw Komorowski also addressed the group, retelling modern Poland’s birth story -- the rise of the Solidarity movement, the support of Pope John Paul II, himself a Pole, and the push to shrug off the Communist government “without even spilling a single drop of blood.”

“We tore down the Iron Curtain of propaganda and lies,” he said. “We tore down the Iron Curtain to be able to live in the truth. ... For the very first time, elections were not a fiction.”

Obama noted the contrast of that peaceful protest with the tanks that crushed protesters in China’s Tiananmen Square on the same day 25 years ago.

“The blessings of liberty must be earned and renewed by every generation -- including our own. This is the work to which we rededicate ourselves today,” Obama said.

Obama spoke on a trip to Europe during which he’s spent much of his time reaffirming the U.S. commitment to defend NATO allies made nervous by Russia’s annexation of Crimea. He repeated those assurances on Wednesday, winning loud applause.

“Article 5 [of the NATO charter] is clear -- an attack on one is an attack on all. As allies, we have a solemn duty -- a binding treaty obligation -- to defend your territorial integrity. And we will,” Obama said.

Though Obama's speech included soaring promises, he has no clear way to fulfill many of them.

Although he declared he would not accept Russia's annexation of Crimea, his administration essentially has -- at least for now -- and has focused its efforts not on persuading Moscow to return the peninsula to Kiev but on trying to prevent additional incursions.

Still, Obama spoke in lofty terms about the future.

“The days of empires and spheres of influence are over,” he said. “Bigger nations must not be allowed to bully the small, or impose their will at the barrel of a gun or with masked men taking over buildings. And the stroke of a pen can never legitimize the theft of a neighbor’s land. So we will never accept Russia’s occupation of Crimea or its violations of Ukraine’s sovereignty.

As he praised the gains of the Solidarity movement, Obama acknowledged Solidarity icon and Nobel Peace laureate Lech Walesa, who has said publicly that he is “displeased” that the American “superpower is not taking the lead” in the world today.

But Obama glossed over the criticism in favor of noting commonality with his audience. Throughout his visit in Poland, the president has mentioned the strong ties to Poland of his hometown of Chicago, where people of Polish descent frequently refer to their city as the world's biggest outpost of Polonia.