Madrid's Temple of Debod

How did an ancient Egyptian temple end up sitting in a park in a European capital city?