The European Union and the British government have clinched a new deal setting the terms of Britain’s exit from the bloc.