He returned to Pistoia in December 1666 to replace his brother as maestro di cappella of the cathedral in June 1667.
Melani was a favorite composer of Cardinal Giulio Rospigliosi (later Pope Clement IX).
The work was written to celebrate the Holy League's victory against the Turks; he gained the commission through the efforts of Pope Innocent XI.
This coupled with the fact that Alessandro’s nephews were made a part of the minor nobility in Tuscany around this time has caused some scholars to speculate that politics played a role in the events surrounding the 1685 commission.
Melani wrote another notable oratorio in 1690, Lo scisma nel sacerdozio (now lost), for Francesco II d'Este.