The announcement that the deal had been signed came after months of fraught negotiations.