BARCELONA, Spain — Since taking charge of Spain six years ago, Prime Minister Mariano Rajoy has done his best to remain aloof from the gathering threat of secessionism in Catalonia.

He did not engage Catalonia’s leadership until it finally declared unilateral independence in October, prompting him to take direct control of the region. Before then, Mr. Rajoy seemed to hope that the problem would eventually fade, along with a Spanish financial crisis that had helped fuel the movement.

But after Catalonia’s regional election on Thursday, in which separatist parties won a majority of seats in the regional parliament, it is now clear that the independence movement is not going away.

Spain is staring at a festering, long-term conflict, unfolding in a deeply divided region and driven by emboldened separatists whose demands could now be harder than ever to ignore.