MADRID — A Spanish judge on Monday ordered the release on bail of six Catalan separatist politicians, just three weeks before regional elections, while keeping four others in custody.

The ruling, which was condemned by Catalan separatists, pointed to the complications of the campaign, which officially opens Tuesday, before the Dec. 21 elections for a new regional Parliament.

Prime Minister Mariano Rajoy of Spain called the elections in the hope that voters would replace the separatists who had used their fragile majority to push through an October referendum on independence that Spanish courts declared illegal.

The central government in Madrid has been administering the region directly since removing the region’s leadership. The former Catalan leader Carles Puigdemont left for Belgium rather than face Spain’s judiciary.