The Spanish prime minister, Mariano Rajoy, has vowed to return Catalonia to the rule of law as his government prepares to announce unprecedented measures to head off the independence crisis by imposing direct rule from Madrid.