The epicenter of the quake was 164 km south-southeast of Gibraltar in the Alborán sea occurring at 5.22am (4 .22 GMT and Melilla) according to the United States Geological Survey.
Spain's north African enclave of Melilla experienced the worst of the quake, with masonry sent tumbling from the façade of buildings, where some 26 people reported sustaining "light injuries".
Residents were told not to get in their cars so as to keep the roads clear for emergency services and the schools were closed to allow inspections for damage.
The quake was also felt across Andalusia from Jaen to Malaga and along the Costa del Sol.
WATCH: Video of the earthquake
The National Geographic Institute reported a total of seven aftershocks.
Here are how some of those woken by the earthquake described the experience.
Deborah Cater commented on The Local Facebook page: "Woke me at 5.23, according to my phone, with the bed moving side to side and all the ornaments and pictures rattling. I'm in Axarquia, east of Málaga."
Wow, we've just had a earthquake - chair moving a lot... #Malaga- Joanna Styles (@Jostyleswriter) January 21, 2016
In Morocco, authorities reported that a 12 year-old boy had died of heart failure after suffering a panic attack during the earthquake, while a 35 year-old was injured after jumping out of a second-floor window during the quake.