Mohamed Houli Chemlal, 21, and three others were charged with terrorist offences over the rampages in Barcelona and a seaside resort that claimed 15 lives.
Mohamed Houli Chemlal, 21, and three others were charged with terrorist offences over the rampages in Barcelona and a seaside resort that claimed 15 lives and wounded more than 100 people.
They are the only survivors of a 12-man cell whose members rammed a van into pedestrians on a tourist-packed boulevard in Barcelona on Thursday and hours later carried out a similar attack in the seaside resort of Cambrils further south.
The four were charged with "belonging to a terrorist organisation, terror-related murder and possession of explosives," said a judicial source, who spoke on condition of anonymity.
The cell was planning "an attack on an even greater scale, targeting monuments," according to the source.
Chemlal, a Spaniard, was injured in an accidental explosion at a makeshift bomb factory on Wednesday evening that killed an imam, Abdelbaki Es Satty, thought to have radicalised him and other young suspects.
Chemlal also said during interrogation that the imam wanted to blow himself up, according to the source.
Police had previously revealed that the suspected jihadists had been preparing bombs for "one or more attacks in Barcelona".
Josep Lluis Trapero, head of police in Catalonia, said 120 gas canisters and traces of TATP components -- a homemade explosive that is a hallmark of the Islamic State group that claimed the attacks -- had been found at their bomb factory.
The accidental explosion in the house in Alcanar, south of Barcelona, may have forced the suspects to alter their plans.
The four men in court included Driss Oukabir, the older brother of Moussa who was killed by police in Cambrils on Friday along with four other suspects.
The others were Mohamed Aallaa, one of three brothers allegedly involved, and Salh El Karib, who manages a store that allows people to make calls abroad.
Chemlal, dressed in hospital patient clothing and with his right hand bandaged, was brought in after a doctor determined he was fit for interrogation, a court spokesman told AFP.
The court hearing of the four suspects caps five days of angst following the twin vehicle assaults.
Spanish police shot dead Younes Abouyaaqoub, the suspected Barcelona van driver, on Monday in a dramatic end to the manhunt for the Moroccan national, who shouted "God is greatest" when he was killed.
He was the last fugitive member of the cell.
Besides the four men detained, the rest were killed, either by police or in the explosion in Alcanar.
While Catalan police say the cell has been dismantled, investigators are trying to determine if it had logistical or other forms of support from other individuals.
Questions are also arising about the group's possible international connections.
In Belgium, the mayor of the Vilvorde region told AFP that Satty spent time in the Brussels suburb of Machelen -- next to the city's airport -- between January and March 2016.
On the other side of Brussels, the Molenbeek suburb has gained notoriety as a hotbed of international jihadists after the Brussels bombings in March 2016 and the Paris attacks in November 2015.
And in France, Interior Minister Gerard Collomb told BFMTV that the Audi used to mow down people in Cambrils had been detected by speed cameras in the Paris region while making "a very rapid return trip" days before the Spanish attacks.
Collomb is due to host Spanish counterpart Juan Ignacio Zoido on Wednesday for talks due to include anti-terrorism cooperation.
At least one of the suspects also spent a night in Zurich in December, according to Swiss police, which said it was too early to speculate about any connections with Switzerland.
'One or more' attacks
Five days on, a clearer picture is emerging of the events that unfolded last week.
Abouyaaqoub used a vehicle to smash into crowds on Barcelona's famous Las Ramblas boulevard, killing 13 people and injuring more than 100.
While on the run, the 22-year-old stabbed to death the driver of a car he hijacked to get away.
Several hours later, a similar vehicle attack in Cambrils saw a car run into pedestrians, with one occupant jumping out and stabbing a woman, who later died.
Police shot dead the five attackers there, some of whom were wearing fake explosive belts.
Abouyaaqoub was gunned down on Monday in a village about 60 kilometres (40 miles) west of Barcelona, after receiving multiple tip-offs.
Police opened fire as he appeared to be wearing an explosive belt, which turned out to be fake.
The victims of the attacks were from three dozen countries including those as far afield as Australia, China and the United States.