Answer
The Treaty of Utrecht, which was signed in 1713, ended the War of the Spanish Succession. It was not until after Joseph I's death that the treaty was signed, and the two major conflicts he faced were not resolved until then. The treaty gave Spain to Philip V, who was a French prince, and Britain received Gibraltar and Minorca.