At times during weeks of thorny negotiations, the efforts of Prime Minister Keir Starmer’s government seemed destined to fail.