BARCELONA — Catalonia’s police force faces a crucial test of its autonomy on Sunday, as it comes under orders from the national government in Madrid to prevent Catalans from voting on their independence.

It is a daunting task for the Catalan police, an autonomous force known as the Mossos d’Esquadra, which has been told to shut polling stations early on Sunday and dislodge people who plan to sleep there overnight. Those Catalans hope to safeguard the referendum, which Spain’s constitutional court has formally suspended.

The Mossos will confront the very citizens who recently praised them for their response to the August terrorist attacks in Catalonia. But Catalans have had an up-and-down relationship with the Mossos, notably over the use of force, and the unit has increasingly been pulled into the politics of the secessionist drive.

For now, however, separatists are confident that the Mossos commanders will stick to their recent pledge to avoid unrest at all costs and perhaps leave to thousands of other Spanish police officers the task of completing a referendum shutdown.