The crash happened at 2.45pm local time (1545 BST) when the jet, which was heading for Las Palmas, in Gran Canaria, attempted to take off.
Witnesses said one of the engines caught fire as the aircraft was leaving the runway. It took to the air momentarily before veering to the right and crashing into the ground between two runways, breaking into two parts.
Reports suggested that the plane had come down on its second attempt to take off.
A civil guard returning from the scene told El País newspaper: “It doesn’t look anything like a plane – it’s horrific. Everything is burnt. It’s the closest to hell that I’ve seen.”
A member of the emergency services described the area as a “war zone.”
Manuel Moleno, a Spanish journalist who was near the area when the accident happened, told the BBC the plane had “crashed into pieces”.
“We heard a big crash,” he said. “So we stopped, and we saw a lot of smoke.”
There were conflicting reports of the death toll, with the Spanish interior ministry saying that more than 100 people had been confirmed dead so far.
Another 19 were said to be in a critical condition, with 25 having suffered less severe injuries. Two babies were thought to be on board.
Spanair, which is owned by the Scandanavian carrier SAS, had a code-sharing arrangement with the Lufthansa flight LH255.
Seven passengers on board the plane were confirmed as Lufthansa passengers, four from Germany. Spanish radio reported that Swedes and Danes were also believed to have been among the passengers.
The Foreign Office said two British officials were at the airport to find out whether any Britons had been on board.
Hundreds of emergency workers and dozens of ambulances and firefighting vehicles were sent to the scene, along with heavy lifting equipment.
Helicopters and fire trucks dumped water on the plane, which ended up in a wooded area at the end of the terminal four runway. Thick columns of white smoke billowed from the scene.
The airport was closed for a number of hours, with passengers being turned away. Some services are now understood to have resumed.
Reporters at the scene said the terminal building had filled up with people either looking for information about relatives on the flight or caught up in the travel disruption.
Unconfirmed reports said the flight had been due to take off at 1pm and had left the departure gate at 1.05pm, returning just over half an hour later because of technical problems.
A Spanair spokesman said it was too early to confirm why the plane, which was 15 years old and was last serviced in January, had crashed.
He said the company’s thoughts were with those who had been injured and the relatives of those who had died.
“Spanair regrets to confirm that its flight number JK 5022, from Madrid to Las Palmas de Gran Canarias, was involved in an incident at Madrid today,” the spokesman said.
“On board were 164 passengers and nine crew members. JK is a code share flight with Lufthansa LH 2554.
“Spanair is doing everything possible to assist the Spanish authorities at this difficult time, and has established a local helpline number for relatives or friends of those who may have been on board.”
An official with the Madrid emergency rescue service said crews were removing the dead and injured from the wreckage. “It is certain catastrophe,” he added.
The US national transportation safety board said it was sending an investigation team to Madrid to help with the crash investigation because the aircraft is American-made.
Spanish media reported that the plane’s black boxes had already been found.