An elaborate sculpted altar was commissioned by the Milanese Confraternity of the Immaculate Conception for their oratory in San Francesco in 1480. A new contract was drawn up in 1483 with Leonardo and the de Predis brothers: a central panel was to be painted by Leonardo alone, and there were to be two side panels showing angels singing and playing musical instruments. Two paintings of angels (An Angel in Green with a Vielle and An Angel in Red with a Lute) by artists influenced by Leonardo, are undoubtedly those for the altarpiece.
'The Virgin of the Rocks' seems not to refer to the mystery of the Immaculate Conception, but depicts the type of subject that Leonardo might have painted in his native Florence where legends concerning the young Saint John the Baptist were popular.
Execution of the commission was protracted. Leonardo may only have put the finishing touches to it in 1508. The finished work was then sent to France, (now Paris, Louvre). Leonardo painted a replacement for San Francesco that was probably completed with some help from his studio in 1508, and which is now in the National Gallery Collection.