Betrothal and marriage
In the second half of the 1650s at the imperial court in Vienna the necessity developed for another dynastic marriage between the Spanish and Austrian branches of the House of Habsburg. The union was needed to strengthen the position of both countries, especially against the Kingdom of France. At first the proposals were for Maria Theresa, the eldest daughter of Philip IV, to marry the heir of the Holy Roman Empire, Archduke Leopold Ignaz. But in 1660 and under the terms of the Treaty of the Pyrenees, Maria Theresa was married to the French King, Louis XIV; as a part of her marriage contract, she was asked to renounce her claims to the Spanish throne in return for a monetary settlement as part of her dowry, which was never paid.
Since her childhood, her parents decided that Margaret would marry a relative from the Austrian branch of the Habsburgs in order to maintain her succession rights within the dynasty. The main marriage candidate was the Holy Roman Emperor Leopold I (who was her maternal uncle and paternal cousin). During that era, people were not aware of the risk of inbreeding. Both the family and diplomatic correspondence of the time reveal that they did not find anything wrong with it. Although the Spanish court hesitated to agree to this proposal, because the infanta could inherit the Spanish crown if her little brother died, both King Philip IV and Queen Mariana strongly wanted their daughter to marry Emperor Leopold I, as their private correspondence with the nun Sor María de Ágreda shows. The title of Holy Roman Emperor was one of the highest-ranking and most prestigious in Europe at that time, so this was a splendid match for Margaret and for the Spanish crown. Therefore, the Holy Roman Emperor was the only serious marriage candidate considered by the Spanish court for Margaret Theresa. In 1659, King Philip IV expressed his desire to offer the hand of his daughter Margaret Theresa in marriage to Emperor Leopold I, through the Spanish ambassador in Vienna. In February 1660, Emperor Leopold officially asked King Philip and Queen Mariana for the hand of Margaret Theresa in marriage, and they accepted in April of the same year. Thus, Margaret became engaged to Emperor Leopold when she was only 8 years old.
Even when the infanta was already betrothed to the Emperor, there were still rumors that Margaret could marry Archduke Charles Joseph of Austria, who was Leopold's youngest brother, and in case the future King Charles II died, then Margaret and Charles Joseph would become the next Spanish monarchs. The fact that the young Archduke was Catholic and a Habsburg made him completely acceptable for the Spanish court, which would never accept a member from another dynasty, and even less a Protestant, as a marriage candidate for Margaret Theresa. In any case, the rumors about a marriage to the Archduke came to nothing and Margaret remained betrothed to Emperor Leopold. At the end of 1662, the Emperor sent Count Pötting to Madrid to conduct marriage negotiations. In October 1662, the new Imperial ambassador in Spain, Count Francis Eusebius of Pötting, began one of his main diplomatic assignments, which was the celebration of the marriage between the infanta and the emperor. Negotiations by the Spanish side were led by Ramiro Núñez de Guzmán, Duke of Medina de las Torres. On 6 April 1663, the betrothal between Margaret and Leopold I was finally announced to the public. In May 1663, Philip IV wrote to the nun Sor María de Ágreda, expressing his happiness at the official and public engagement of his daughter Margaret to Emperor Leopold. The marriage contract was signed on 18 December. Before the official wedding ceremony (which, according to custom, had to take place in Vienna) another portrait of the infanta was sent, in order for the emperor to know his bride.
King Philip IV died on 17 September 1665. In his will, he mentioned Margaret's marriage to Emperor Leopold I, and stated that, if her younger brother died, then Margaret would inherit the Spanish throne, and Queen Mariana would act as regent, in case the infanta and her husband, the Emperor, were abroad. This means that Philip IV's idea was that, if Charles II died, then Margaret and Leopold would become joint rulers of Spain, even if they were absent. After Philip IV's death, Mariana asked the ministers to confirm Margaret’s marriage to Leopold I, which they did. On 25 April 1666, the marriage by proxy was finally celebrated in Madrid, in a ceremony attended not only by the Dowager Queen, King Charles II and the Imperial ambassador but also by the local nobility; the groom was represented by Antonio de la Cerda, 7th Duke of Medinaceli.
On 28 April 1666 Margaret traveled from Madrid to Vienna, accompanied by her personal retinue. The infanta arrived at Dénia, where she rested for some days before embarking on the Spanish royal fleet on 16 July, in turn escorted by ships of the Order of Malta and the Grand Duchy of Tuscany. Then (after a short stop in Barcelona because Margaret had some health issues) the cortege sailed to the port of Finale Ligure, arriving on 20 August. There, Margaret was received by Luis Guzman Ponce de Leon, Governor of Milan. The cortege left Finale on 1 September and arrived in Milan ten days later, although the official entry was not celebrated until 15 September. After spending almost all September in Milan, the infanta continued the journey through Venice, arriving in early October in Trento. At every stop Margaret received celebrations in her honor. On 8 October the Spanish retinue arrived at the city of Roveredo, where the head of Margaret's cortege, Francisco Fernández de la Cueva, 8th Duke of Alburquerque officially handed the infanta to Ferdinand Joseph, Prince of Dietrichstein, and Count Ernst Adalbert von Harrach, Prince-Bishop of Trent, representants of Leopold I. On 20 October the new Austrian cortege left Roveredo, crossing Tyrol, through Carinthia and Styria, and arrived on 25 November at the district of Schottwien, twelve miles from Vienna where the emperor came to receive his bride.