The church was built in the 1620s-1630s by King Felipe III along with a hostel and hospital for the Portuguese migrants who moved to Madrid when Portugal was under Spanish rule.
When Portugal gained independence, Phillip IV's Queen, Mariana de Austria, dedicated the refuge to German immigrants, and changed names.
King Phillip V gave the administration of the church over to the Hermandad del Refugio (Fraternity of Sanctuary), and this group continues to manage it today, offering food and shelter to the homeless of Madrid.
On one occasion at the Spanish court, the Queen apparently asked him what his wife looked like, and he proceeded to include her image in the painting he had before him.
Francisco Ricci was the son of an Italian painter, and came to Madrid to work on the decorations at the Escorial Monastery under Federico Zuccaro.