RIGA, Latvia — Near midnight on the outskirts of the Latvian capital, close to 100,000 spectators joined 16,500 singers last week in a song about a mystical castle that is submerged when foreign powers hold sway only to rise again.

The castle is a metaphor for their nation. The foreign powers?

Well, from the 20th century, take your pick. First it was the Russians. Then the Germans. Then the Russians again. Only in the last quarter-century has Latvia been able to reclaim its nationhood, and only in the last decade has it felt secure in that claim.

The security came from one thing: joining NATO, an alliance of nations forged after the fires of World War II and expanded during the Cold War as a buffer against Soviet aggression.

Now, with Russia once again on the prowl, that alliance seems to be at risk in ways that were virtually inconceivable when Latvia joined in 2004.