Police said they tracked 22-year-old Younes Abouyaaqoub to a rural area near Barcelona and shot him after he held up what looked like an explosives belt and shouted "Allahu Akbar" (God is Greatest). The bomb squad used a robot to approach his body.
Abouyaaqoub had been on the run since Thursday evening, after he drove at high speed into throngs of strollers along Barcelona's most famous avenue, Las Ramblas. After fleeing the scene, he hijacked a car and fatally stabbed its driver.
ISIS claimed responsibility for the attack, which police believe was planned by a dozen accomplices, including a brother and two first cousins of the Moroccan-born Abouyaaqoub.
Abouyaaqoub had been the only one of 12 accomplices still at large. His mother, Hannou Ghanimi, had appealed for him to surrender, saying she would rather see him in jail than dead.
Of the other 11 in the terrorist cell, five were shot dead by police hours after the van attack, two were killed and one injured the day before in a blast in a house where they were apparently making explosives, and three were arrested elsewhere.
"Shortly before 5 p.m., the police shot down Younes Abouyaaqoub, the driver of the van in the attack that killed 14 people in Barcelona," Carles Puigdemont, head of the Catalonia regional government, told a news conference. He said the bomb belt turned out to be a fake one.
An employee at a petrol station, along an empty stretch of road between the towns of Subirats and Sant Sadurni d'Anoi, spotted a man resembling Abouyaaqoub and called the police.
Sant Sadurni Mayor Maria Rosell said all police forces in Catalonia converged on the town. Police found Abouyaaqoub hiding in vineyards and shot him dead a kilometre down the road next to a sewage treatment plant.
Cristiano Pecchi, an Italian tourist, first heard gunfire at around 4 p.m. (1400 GMT) Shortly afterwards, he said, up to 30 police cars arrived along with helicopters and ambulances.
"I was just waiting for my car to be fixed and suddenly we heard gunfire and all hell was let loose," he said.
The scene unfolded 40 km (25 miles) from the spot, close to the FC Barcelona soccer stadium on the outskirts of the city, where police said Abouyaaqoub had seized the hijacked car.
Police said Abouyaaqoub had first fled Las Ramblas on foot amid the chaos of the attack, then commandeered the car, stabbing the driver, 34-year-old Pau Perez, to death before smashing his way through a police checkpoint and ditching the car in the nearby town of Sant Just Desvern.
The four people arrested so far in connection with the attacks are three Moroccans and a citizen of Spain's North African enclave of Melilla. They were taken on Monday to the high court in Madrid, which has jurisdiction over terrorism matters.
Abouyaaqoub lived in Ripoll, a town in the Pyrenees mountains north of Barcelona close to the French border.
ISIS also claimed responsibility for a separate deadly assault, hours after the van attack, in the coastal resort town of Cambrils, south of Barcelona.
In Cambrils, a car rammed into passersby and its occupants got out and tried to stab people. The five assailants were shot dead by police, while a Spanish woman died in the attack.
In the roughly seven hours of violence that followed the van's entry into the central promenade of Las Ramblas on Thursday afternoon, attackers killed 15 people: 13 on Las Ramblas, the Cambrils victim and the man in the hijacked car.
Of the 120 injured on Las Ramblas, eight remain in a critical condition in hospital.
It was the deadliest attack in Spain since March 2004, when Islamists planted bombs on commuter trains in Madrid, killing 191 people, and the latest in a series of vehicular assaults on civilians in European cities claimed by ISIS.
Two of the suspected plotters in Barcelona, including an imam thought by police to have helped radicalise his young conspirators, were killed on Wednesday night in what is believed to have been an accidental explosion.
About 120 butane gas cylinders were found at the scene of the blast, a house in the town of Alcanar, south of Barcelona. Police believe the pair were preparing a much larger attack with explosives, but the blast prompted their accomplices to adopt a new, less elaborate plan.
Spanish police said the international investigation was still open and have sought information on a visit the imam, Abdelbaki Es Satty, made to Belgium last year, said Thierry Werts, spokesman for the Belgian federal prosecutor's office.
Hans Bonte, mayor of the Belgian town of Vilvoorde, near Brussels, told VRT television at the weekend the imam had been there looking for work. Belgium has suffered several Islamist attacks and Vilvoorde has been a centre of Islamic radicalism.
The van driver, Abouyaaqoub, began showing more religiously conservative behaviour over the past year, said relatives in his native Morocco. He refused to shake hands with women during a visit to his birthplace in March, they said.
Abouyaaqoub's brother El Houssaine and first cousins Mohamed and Omar Hychami were among those killed by police in Cambrils. They were all originally from the small Moroccan town of Mrirt.
(Additional reporting by Inmaculada Sanz, Sarah White and Julien Toyer in Madrid, Julia Fioretti in Brussels; Writing by Mark Bendeich; Editing by Mark Heinrich)