The sanctuary entirely carved in stone, according to popular folklore, was a refugee of the saint, then a Portuguese missionary named Fernando Martins de Bulhões, whose ship had been rerouted by a violent storm during a trip to his native Lisbon in 1221.
After his death in 1231 and his canonisation in 1232, the cave was transformed first into a place of prayer and then a sanctuary after various structural interventions in 1575, 1737, and 1783.