Spain’s prime minister has clinched agreement with Catalan separatists, officials said on Thursday, in a deal that will enable him to remain in power but that has raised tensions and sparked protests in the country.