Twelve people have been killed and 80 injured after a white van careered into a crowd in La Rambla district of Barcelona.
The street is popular with tourists due to its variety of market stalls, bars and restaurants.
Police have arrested one person in connection with the attack.
Sturgeon expressed her condolences to all those affected, including Glasgow University rector Aamer Anwar who was in the city for a conference. He was in the area at the time of the attack.
She tweeted: “My thoughts are with everyone affected by the horrific and mindless attack in Barcelona.
“Also thinking of my good pal @AamerAnwar who, with many others, witnessed the attack in Barcelona. Stay safe.”
The attack - the first major terror-related killing on Spanish soil since more than 190 people died in the Madrid train bombs in 2004 - brought widespread condemnation.
Mrs May denounced the “terrible” assault in the Spanish city which saw a van plough into pedestrians and follows a spate of similar attacks in London in recent months.
She said: “My thoughts are with the victims of today’s terrible attack in Barcelona and the emergency services responding to this ongoing incident.
“The UK stands with Spain against terror.”
Meanwhile, US president Donald Trump wrote on Twitter: “The United States condemns the terror attack in Barcelona, Spain, and will do whatever is necessary to help. Be tough & strong, we love you!”
Sadiq Khan said London stood with Barcelona “against the evil terrorism” following recent attacks in Westminster, London Bridge and Finsbury Park.
Mr Khan wrote on Twitter: “My thoughts are with the victims of this barbaric terrorist attack in the great city of Barcelona and with their brave emergency services.
“London stands with Barcelona against the evil of terrorism.”
A number of other high-profile figures also voiced support for the Barcelona victims.
Labour leader Jeremy Corbyn tweeted: “Terrible reports from Barcelona. My thoughts are with those killed and injured, and the emergency services working to save lives.”
Foreign Secretary Boris Johnson said: “Concerned and saddened by #Barcelona attack. Our thoughts are with those affected. Doing all we can to identify whether Brits need help.”
US First Lady Melania Trump wrote: “Thoughts and prayers to #Barcelona.”
Barcelona FC said it was “deeply saddened” by the attack, while their rivals Real Madrid expressed “solidarity with the victims and their families and friends”.
Former England striker Gary Lineker, who played for Barcelona for three seasons from 1986-89, tweeted: “Deeply saddened to hear about the attack in the wonderful city of Barcelona. What purpose this barbarity serves is beyond comprehension.”
Manchester City manager Pep Guardiola, a former Barcelona midfielder and coach, said: “All at MCFC are saddened to hear of the attack in the City of Barcelona. Our thoughts are with all affected and the emergency services.”
Spanish tennis champion Rafael Nadal, whose uncle Miguel Angel Nadal used to play for Barcelona, said: “Shattered by what has happened in Barcelona! All my support for the families affected and the city.” Sue Murphy, deputy leader of Manchester City Council, said: “Our hearts go out to Barcelona in the wake of this sickening incident.
“Manchester stands in solidarity with that great city. We know from recent experience both how devastating this sort of attack is and how important international solidarity, community spirit and a refusal to give in to terror are in dealing with its aftermath.”