Dispute over Gibraltar had threatened to derail Brexit deal