Sweden’s government clinched a last-minute deal to ensure its justice minister would survive a no-confidence vote in parliament, averting a political crisis.