LLIVIA, Spain — The Spanish police cracked down on parts of Catalonia in an attempt to halt an independence referendum on Oct. 1, wielding truncheons, firing rubber bullets and barring polling stations.

But in little Llivia, the small cobblestone square in the town center was packed with a celebratory crowd. The atmosphere was so festive that Rosario Cortizo, 67, who runs a restaurant and hostel with her husband, decided to organize a barbecue for the voters.

“We have been waiting for this day for a very long time,” Ms. Cortizo said joyfully.

On that day, the people of Catalonia were voting on whether or not to be a part of Spain. But for Llivia, a quaint town tucked about 4,000 feet up in the foothills of the Pyrenees, an important part of that decision was made centuries ago.

Llivia is already separated from Spain physically: The five-square-mile municipality is a geographic anomaly resulting from a quirk of the 1659 Treaty of the Pyrenees, which settled a more-than-two-decade round of fighting between Spain and France.