The Madonna and Child with Saint Anne was painted between 1605 and 8 April 1606, when a final payment to Caravaggio was recorded, for the Confraternity of Sant' Anna dei Palafrenieri, or Grooms, of the Vatican Palace. The composition depicts Christ and the Virgin treading simultaneously on the serpent of heresy, watched by the Virgin's mother, St. Anne, who was the patron saint of the Palafrenieri. It was an unusual although topical theme based on an ambiguous biblical passage, Genesis 111:15, which does not make it clear whether it was Eve, the antetype of Mary, the 'New Eve', or her offspring who was meant to strike at the serpent's head. What started as a theological dispute became caught up in the wider debate between Roman Catholicism and Protestantism, with the Protestants not unnaturally arguing in favour of the offspring and, hence, Christ. The issue was resolved on the Roman Catholic side, however, with commendable textual accuracy, not to say religious tact, by a Bull of Pius V which ruled that 'the Virgin crushed the head of the serpent with the aid of him to whom she had given birth.' It is this interpretation which Caravaggio followed, possibly basing himself on a slightly earlier picture by the Milanese artist Figino.
For all its evocative characterization, the Madonna of the Serpent is among the least successful of Caravaggio's mature works, with the somewhat stiff figures swamped by the darkness of the room. Despite its orthodox iconography, the picture was apparently thought indecent by the authorities and removed from its altar in St. Peter's after only two days (14-15 April). It was then kept in the church of the Palafrenieri until June, when it was sold to Cardinal Scipione Borghese, who housed it away from the public gaze in his own private collection.