The video tweeted by EU border agency Frontex shows the 34 migrants travelling on board a black boat Sunday when flames suddenly erupted at the back near the engine, and rapidly spread through the small vessel.
The migrants, most of whom appear to be wearing life jackets, jump into the water according to images caught on camera by a Portuguese air force plane helping Frontex with maritime surveillance, which threw them a small lifeboat and notified Spanish coastguards.
Some were able to scramble onto the lifeboat while others held onto their sinking vessel, the coastguards said in a statement.
A helicopter and several boats were dispatched to the area southwest of Alboran Island between Morocco and Spain.
Tomas Garcia, a manager at the coastguard centre in Spain's southeastern Almeria province who has 24 years experience coordinating rescues was quoted as saying in the statement that this "was one of the most complex" his centre had seen.
A fisherman sailing in the area also helped in rescue efforts.
The migrants, whose nationalities were not disclosed, were finally taken safe and sound to the port of Motril in southern Spain.