On 12 April 1941, Federico Romero, Commander of the 14th Infantry Division Isonzo, declared the military and civilian takeover of Ljubljana. This was followed by assuming control over the civilian police and the gendarmerie. The supreme authority of the province passed on 18 April from Ban Marko Natlačen to High Commissioner Emilio Grazioli, and on 3 May 1941 the Province of Ljubljana was annexed by Italy. The Slovenian population was not granted Italian citizenship; rather, they were made citizens by virtue of annexation.
To maintain the appearance of self-government, the Italians kept the administrative structure of Ljubljana; Grazioli even invited the city council to participate, yet all the important positions went to Italians. This is also how the mayor issue was settled; per a decree from January 1942 the high commissioner had the power to appoint and dismiss (deputy) mayors whose decisions were executed by municipal secretaries. Grazioli appointed Leon Rupnik to act as mayor of Ljubljana, and Franc Jančigaj as his general secretary, with the Italian Salvatore Trachida serving as deputy mayor.
The subsequent capitulation of Italy and arrival of Germans meant a major administrative change for the Province of Ljubljana which was now part of the Operational Zone of the Adriatic Littoral with headquarters in Trieste, administrated by Friedrich Rainer, Nazi Gauleiter of Carinthia; it was also part of the Republic of Salò. Mussolini re-appointed Emilio Grazioli as its High Commissioner – a decision met with opposition by Rupnik's circle. In a bid to avoid conflict, the Germans prevented Grazioli to assume the position. Initially, no particular candidate was considered for the leadership of the autonomous administration in Ljubljana. Following Bishop Gregorij Rožman's suggestion, on 20 September 1943 Rainer appointed General Leon Rupnik, the current Mayor of Ljubljana, to act as the head of the provincial administration. Rupnik thus became the only Slovenian prefect in the Operational Zone of the Adriatic Littoral – the rest were all Italian. Prefects acted alongside a designated German advisor. In Ljubljana this was originally Herman Doujak who had to step aside in October 1943 for Erwin Rösener, Higher SS and Police Leader of the Province of Ljubljana.
No new Ljubljana mayor was appointed during German occupation, and general secretary Jančigaj performed mayoral duties as per the relevant decree until liberation. Upon liberation on 9 May 1945, the administrative management was assumed by the temporary city field committee. Ten days later the City Committee of the Liberation Front was elected, with Pavel Lunaček serving as president.