MADRID (Reuters) - Nationalists regained control of Catalonia’s government on Saturday and immediately pledged to seek independence for the wealthy region, posing a swift challenge to new Spanish Prime Minister Pedro Sanchez who took office on the same day.

FILE PHOTO: Newly elected Catalan regional leader Quim Torra speaks to reporters outside the Estremera prison where he visited former Catalan cabinet members Oriol Junqueras, Jordi Turull, Joaquim Forn, Josep Rull and Raul Romeva who are jailed there pending trial on charges of sedition, rebellion and misappropriation of funds, in Estremera, Spain, May 21, 2018. REUTERS/Sergio Perez

The new Catalan cabinet was sworn in after months of tensions with the central government, ending Madrid’s seven-month direct rule of the region, imposed by Sanchez’s predecessor after separatists declared independence.

Sanchez, a Socialist who has said he wants talks on Catalonia but opposes any independence referendum, was sworn in about an hour earlier on Saturday, a day after parliament ousted conservative Mariano Rajoy over a corruption scandal.

The unexpected coincidence of the central and regional governments taking power minutes apart could open a new chapter after dramatic months that have seen Catalan politicians jailed or flee abroad to avoid arrest.

Both sides have said they want to talk. But they have very different targets: Sanchez’s Socialists had backed Rajoy’s Catalonia policy, opposing independence.

“This government is committed to moving towards an independent state in the form of a republic,” Catalonia’s new leader Quim Torra said after the cabinet’s swearing in ceremony in which separatists shouted “Llibertat! Llibertat!” (Freedom!).

He called on Sanchez, an untested lawmaker who has never been in government, to meet and talk about Catalonia’s future.

“Let’s talk, let’s deal with this question, let’s take risks, you and us. We need to sit around the same table and negotiate, government to government,” he said.

Sanchez, who secured the backing of an unlikely alliance of mainstream Socialists, hard-leftists and Catalan and Basque nationalists to bring down Rajoy, has the slimmest parliamentary majority since the birth of Spanish democracy in 1975.

His Socialists hold just 84 seats in the 350-member assembly, which could make any bold move on the economic or political front - including on Catalonia - difficult.

He has already said he would stick to the 2018 budget crafted by Rajoy’s conservatives.

Rajoy imposed Madrid’s direct rule on Catalonia after nationalists organized an independence referendum deemed illegal by Spanish courts. Rajoy then organized snap elections in Catalonia in December, hoping opponents of independence would win, but that backfired when voters gave separatists a majority.

It took several tense months after the snap elections for the Catalan nationalists to finally get approval for a new regional government, after several failed attempts when Madrid barred jailed candidates or those in self-imposed exile, such as former regional leader Carles Puigdemont, from office.

The Catalan cabinet includes eight men and six women, with Elsa Artadi as spokeswoman, replacing Jordi Turull who served under Puigdemont and is in custody awaiting trial for his part in the independence drive.