Answer by taking a quote from the following article:

Tosca (Italian pronunciation: ['toska; 'toska]) is an opera in three acts by Giacomo Puccini to an Italian libretto by Luigi Illica and Giuseppe Giacosa. It premiered at the Teatro Costanzi in Rome on 14 January 1900. The work, based on Victorien Sardou's 1887 French-language dramatic play, La Tosca, is a melodramatic piece set in Rome in June 1800, with the Kingdom of Naples's control of Rome threatened by Napoleon's invasion of Italy. It contains depictions of torture, murder and suicide, as well as some of Puccini's best-known lyrical arias.

According to the libretto, the action of Tosca occurs in Rome in June 1800. Sardou, in his play, dates it more precisely; La Tosca takes place in the afternoon, evening, and early morning of 17 and 18 June 1800.  Italy had long been divided into a number of small states, with the Pope in Rome ruling the Papal States in central Italy. Following the French Revolution, a French army under Napoleon invaded Italy in 1796, entering Rome almost unopposed on 11 February 1798 and establishing a republic there. Pope Pius VI was taken prisoner, and was sent into exile on February 20, 1798. (Pius VI would die in exile in 1799, and his successor, Pius VII, who was elected in Venice on 14 March 1800, would not enter Rome until July 3. There is thus neither a Pope nor papal government in Rome during the days depicted in the opera.) The new republic was ruled by seven consuls; in the opera this is the office formerly held by Angelotti, whose character may be based on the real-life consul Liborio Angelucci. In September 1799 the French, who had protected the republic, withdrew from Rome. As they left, troops of the Kingdom of Naples occupied the city.  In May 1800 Napoleon, by then the undisputed leader of France, brought his troops across the Alps to Italy once again. On 14 June his army met the Austrian forces at the Battle of Marengo (near Alessandria). Austrian troops were initially successful; by mid-morning they were in control of the field of battle. Their commander, Michael von Melas, sent this news south towards Rome. However, fresh French troops arrived in late afternoon, and Napoleon attacked the tired Austrians. As Melas retreated in disarray with the remains of his army, he sent a second courier south with the revised message. The Neapolitans abandoned Rome, and the city spent the next fourteen years under French domination.

When did the Neapolitans abandon Rome?
In May 1800