The flight left at 2037 GMT yesterday and returned to Madrid while flying over Morocco, according to a map published by the G1 news website.
TAM "was notified by Spanish authorities of an alleged bomb threat aboard Flight JJ8065. The plane returned to its airport of origin, landing safely," the airline said on Twitter.
Another TAM flight on the same route was forced to make an emergency landing due to turbulence in September 2013, injuring 15 people.