By Michael Birnbaum, William Booth and William Branigin, The Washington Post

BRUSSELS – Spain came under repeated attack starting Thursday in what authorities called linked terrorist incidents, when a driver swerved a van into crowds in Barcelona’s historic Las Ramblas district, killing more than a dozen people and injuring scores of others. Early Friday, an attempted attack unfolded in a town down the coast. The Islamic State claimed responsibility for the Barcelona violence.

The initial attack broke the peace of a warm summer afternoon in a packed, tourist-friendly area of Barcelona at the peak of vacation season, and the victims came from well beyond the city’s borders. Authorities said that 15 people had suffered serious injuries and that the death toll could rise. More than 100 people were hurt, said Joaquim Forn, the interior minister of the Catalan regional government.

Josep Lluís Trapero, a senior Catalan police official, told reporters that two men were arrested in connection with the attack, a Moroccan national and a Spanish citizen from the enclave of Melilla. The driver is still thought to be at large, he said.

Early Friday, police said they thwarted what they thought was an attempt at a second, connected attack, in the Catalan town of Cambrils, 60 miles southwest of Barcelona, by fatally shooting four suspects. A fifth suspect later died of his injuries. Seven other people were injured in the incident, including a police officer, police said. They offered no additional details.

Amateur video aired by Spain’s state TVE broadcaster showed several police cars speeding along what appeared to be a seafront boulevard as people screamed, followed by a brief volley of about 10 bullets.

A second video showed three bodies on the ground in front of the town’s yacht club.

Authorities later carried out controlled detonations of the suspected explosives.

Spain had been spared a large-scale terrorist attack since the 2004 bombing of the Madrid rail system that killed 192 people and injured about 2,000, but authorities had long braced for another hit. The attack Thursday brought to Spain the same sort of vehicular carnage that has visited Britain, France, Germany and Sweden since 2016, and highlighted the difficulty of defending dense city centers from violence that requires no explosives or training.

“Terrorists will never defeat a united people who love freedom in the face of barbarism,” Spanish Prime Minister Mariano Rajoy wrote via Twitter as he rushed to Barcelona.

The Islamic State’s Amaq news agency said that “the people who executed the Barcelona attack are soldiers from the Islamic State and they did this operation as a response to calls to target coalition states.” Spain is a member of a broad U.S.-led coalition battling the Islamic State.

It was not immediately clear how closely the Islamic State had worked with the attackers. The group has previously claimed responsibility for attacks inspired by its rhetoric but not directly planned by Islamic State leaders.

Police later said they were looking into a potential link between the van attack and a pair of explosions that destroyed a house in Alcanar, about 100 miles southeast of Barcelona, earlier in the day. One person was killed there and 16 were injured, including police officers and firefighters who were investigating the initial blast. The blast at the house, which apparently contained propane canisters, was initially reported to be a gas explosion.

The connection was not fully explained, but it raised the question of whether the attackers were attempting to use gas canisters in Las Ramblas to cause even more casualties.

The Thursday attack, which took place over a few terror-filled minutes just before 6 p.m. local time, set off a wave of panic and confusion as authorities sought to track down the perpetrator, and fearful people hid for hours in barricaded shops, restaurants and churches.

Witnesses described chaos as the white delivery van suddenly swung off a street and onto the wide pedestrian mall that draws strolling tourists and residents to its bars, cafes and shops. As people started to run away, the driver swerved the vehicle from side to side, in an apparent effort to inflict more damage.

When the van came to a halt, its front was smashed and crumpled inward from the impact of the people hit. People were sprawled on the sidewalk, some not moving. Hats, handbags and other items were strewn about.

“All of sudden, everyone started running, so we ran, too,” Andrew Roby, 35, who was visiting from Washington, said in a phone interview.

Roby said he saw several people, apparently wounded, lying in front of and beside the van.

“We saw people on the ground,” he said. “I heard a bunch of people screaming.”

Some locals expressed frustration at authorities’ failure to place barricades at the entrances to the boulevard in a new era of vehicular terrorism. Las Ramblas is one of the city’s top tourist areas, with a wide pedestrian promenade flanked by roadways.

The van was “going entirely too fast. It looked to me as if he was going left to right, hitting people with the little stand,” Tom Markwell, another American tourist, told the BBC. “All of a sudden, people were just screaming and running.”

One British tourist said she hid beneath the counters of a phone shop with 20 other people for half an hour.

“We heard gunshots and people were running and screaming,” said Mandy Wood.

“By the grace of God, we could have been here two minutes earlier,” she said. “We would have been on the street where it happened.”

Another witness said police suddenly told the crowd to run.

“There was a really loud kind of crashing noise. I didn’t stop to look back,” Ethan Spieby, a witness caught up in the commotion, told the BBC.

Hours after the attack, he said he was holed up in a church with about 80 tourists and locals.

“They have locked the doors, and I think the police are outside. We’re just waiting in here right now to hear more news. It’s quite scary to be caught up in it,” he said.

More than four hours after the attack, police finally started evacuating those who were hiding in nearby buildings.

Citizens of Australia, Belgium, Germany and the Netherlands were among the dead and injured, said officials from those countries, a measure of the international draw of the cosmopolitan Las Ramblas area, which has long stood at the heart of Barcelona.

Underlining the confusion after the attack, police found the identification card of one local resident in the cab of the van and spent hours searching for him. After his name was widely circulated in local media, he turned himself in to police and said that he had lost his identification card, a security official said, speaking on the condition of anonymity to discuss an open investigation.

And adding to the sense of unease, the Catalan Interior Ministry said late Thursday that a car broke through a police checkpoint outside Barcelona and injured two officers. It was not immediately clear whether the incident, which took place near the town of Sant Just Desvern, just west of Barcelona, was connected to the attack.

Spanish police did not immediately give details about the driver or the incident.

After the attack, Spanish authorities shared the names of at least two people with European and Arab intelligence agencies, but the suspects did not appear to have been flagged for connections to extremism, according to an Arab and a European intelligence official, neither of whom was authorized to speak on the record.

Authorities appear to think that a small group of two or three people planned the attack, the Arab intelligence official said.

Catalan authorities said they will stand firm in the face of terrorism.

“There have been people arrested, and this investigation is still ongoing,” Carles Puigdemont, president of the Catalan regional government, told reporters in Barcelona. “Catalonia will always prevail in the face of terrorism. We will always stand for democracy and freedom. We will always be united.”

Islamic State supporters celebrated the Barcelona attack Thursday and promoted previous threats made against Spain, according to the SITE Intelligence Group, which monitors extremist activity.

The Islamic State, also known as ISIS, has called on supporters to carry out attacks using vehicles. The group has claimed responsibility for car attacks in Europe, as well as at Ohio State University last year.

After the attack Thursday, offers of assistance flooded in from around the world, including the United States.

“The United States condemns the terror attack in Barcelona, Spain, and will do whatever is necessary to help. Be tough & strong, we love you!” President Trump wrote via Twitter.

Later in the day, Vice President Pence said that the United States would punish the perpetrators.

“Whoever is responsible should know that the United States of America, together with our allies, will find and punish those responsible, and drive the evil of radical Islamic terror from the face of the Earth,” he told reporters in Panama City, where he is wrapping up a tour of Latin America.

Secretary of State Rex Tillerson said U.S. authorities will offer to help in any way they can.

The Catalonia region of Spain has faced repeated terrorist attacks over decades from the ETA Basque separatist group. Catalonia is planning an independence vote Oct. 1 over the objections of the national government in Madrid, which calls it unconstitutional.

In July 2016, a truck was driven into Bastille Day crowds along a seaside corniche in the southern French city of Nice, killing 86 people. In December 2016, 12 people were killed when a driver used a hijacked truck to drive into a Christmas market in Berlin.

In March, a man in a rented sport-utility vehicle plowed into pedestrians on London’s Westminster Bridge, killing four people before he ran onto the grounds of Parliament and fatally stabbed a police officer. A month later in Stockholm, a rejected asylum-seeker from Uzbekistan crashed a truck into a central department store in an attack that killed five people.