"From Spain come neither good winds nor good marriages" - goes an old Portuguese saying, and indeed between 1580 and 1640 Portugal became a part of the Iberian Union, which was formed between the Crown of Portugal and the Crown of Spain as a result of the Portuguese crisis of dynastic succession.
All kings of the Iberian Union came from the House of Hapsburgs and were invariably named Philip, of which King Philip II of Spain became King Philip I of Portugal and the Algarves after the extinction of the Portuguese royal line and the final defeat of the main Portuguese claimant to the throne, starting the Philippine dynasty in Portugal.
In the meantime Spanish and Portuguese Empires had to unite their overseas possessions as well, which led to an uneasy union of multiple kingdoms and territories governed by six separate Councils. Some twenty years into the Iberian Union all territories in Africa, Persian Gulf, India and South East Asia were attributed to the Council of Portugal, with notable exception of the Philippine Islands (northern and central part of the modern day Republic of the Philippines), which was given to the Council of the Indies.
While the Portuguese nobility was enjoying their status under Philip I and Philip II back in Portugal, things were gradually getting out of control in the overseas territories with more and more income from trade now being diverted to Spain. From 1580 onward Spanish were increasingly trying to interfere in Macau affairs to get a share of lucrative trade.
To adjust to the new reality Macau decided to create the new Municipal Council in 1583 (also known as 'Senado da Câmara'), which administered and governed directly the Portuguese establishment in Macau until the arrival of the first Governor of Macau in 1623. With the creation of Senado, Macau received its official name of the "City of the Holy Name of God of Macau" ("Cidade do (Santo) Nome de Deus de Macau"). The city's prosecutor, who was making part of the Council received title of Mandarin in 1584 from Chinese Emperor, which further strengthened the position of Senado.
Added enormous distances and spirit of resistance, Macau never hoisted Spanish flag during all 60 years of the Iberian Union.
After restoration of monarchy in Portugal Macau's loyalty was highly recognized by King Dom João IV who ordered to change the official name of the city to "CIDADE DO (SANTO) NOME DE DEUS DE MACAU, NÃO HÁ OUTRA MAIS LEAL" adding "there is none more Loyal" to the original name.
Senado continued playing an important role in administration of Macau, although its functions were changing over time. In 1810 King D. João VI of Portugal officially awarded the name 'Leal Senado' in recognition of the 1809 victory in the Battle of The Tiger's Mouth (modern day Humen 虎門) against the pirates of Cam Pau Sai (Quan Apon Chay or Zhang Baozai).
To the present day Macau has Senado Square, Leal Senado Building and Avenue of Dom João IV.
(Sources: Crónicas Macaenses, "Esboço da História de Macau" by Arthur Levy Gomes, Wikipedia)