During his life, Pedro II had worked a long time to secure John a marriage with an Austrian archduchess in order to guarantee Portugal's alliance with the Habsburgs. John continued these negotiations and finally succeeded in negotiating a deal. On 27 June 1707, Fernão Teles da Silva, Count of Vilar Maior, signed a marriage contract with Holy Emperor Joseph I that made official a match between John and the emperor's sister, the Archduchess Maria Anna of Austria. The contract also set the archduchess's dowry at 100,000 crowns, a vast sum for the day.