Before his ascension to the throne, Maha Thammaracha was known as Khun Phirenthorathep or "Okya Phitsanulok" (,
okya being a high-ranking noble title conferred by the king). He descended from the Phra Ruang dynasty of the former
Sukhothai Kingdom, which had been conquered by the
Ayutthaya Kingdom in 1438. It was however not simply annexed, but its area—now known as the "northern cities"
(Mueang Nuea)—continued to be ruled by local aristocrats under Ayutthayan overlordship within the "
mandala" model. During the reign of
Borommatrailokkanat (1448–1488) however, the power of Sukhothai lords was reduced. Phitsanulok, then the most important of the "northern cities", was subsequently ruled by
Uparajas (viceroys), the designated heirs to the throne of Ayutthaya. King
Chairachathirat (1534–1546), who before his ascension to the throne of Ayutthaya had resided as Uparaja in Phitsanulok, centralised the administration even further, abolishing the quasi-autonomous rule of Uparajas and summoning members of the old Sukhothai nobility to serve at his court in Ayutthaya. Khun Phirenthorathep was one of the Sukhothai nobles brought to the court of Ayutthaya by Chairachathirat, who appointed him as head of the royal guard. In 1548, the kingdom fell under the governance of
Worawongsathirat and Chairachathirat's widow
Si Sudachan of the Uthong dynasty. Since the establishment of the kingdom of Ayutthaya, the Uthong (also known as "Lavo-Ayutthaya") dynasty and the
Suphannaphum dynasty (to which King Chairachathirat belonged) had competed for power and fought over the throne. The Uthong clan rose to power at the expense of other clans. In gratitude for putting him on the throne, Maha Chakkraphat made Khun Phirenthorathep ruler of Phitsanulok and conferred him the semiroyal title of Maha Thammaracha. This was in line with the reigning name of Sukhothai kings in the 14th century. Maha Thammaracha enjoyed a great power and may be referred to as a viceroy of the northern provinces. He married
Maha Chakkraphat's daughter, Sawatdirat (later Queen
Wisutkasat). ==Viceroy of Phitsanulok==