Global Affairs Canada says Canadians should avoid the Las Ramblas tourist area in Barcelona and anyone who is already there should stay indoors and follow the instructions of the authorities.
The advisory came after someone drove a van into a crowd on the popular tourist street near the centre of the city, killing at least 13 people and injuring many more.
There was no immediate word on whether any Canadians are among the victims.
The department urged Canadians in Spain to let their "loved ones know you are safe.''
Prime Minister Justin Trudeau said in a statement that he was "deeply saddened'' by the news.
Canada condemns today's terror attack in Barcelona – our hearts, sympathies & support are with the victims and their families.— Justin Trudeau (@JustinTrudeau) August 17, 2017
"While we cannot ignore the outrage we feel, together we must renew our commitment to protect the freedom found in societies that promote unity, openness and inclusion,'' wrote Trudeau, who has been out of the spotlight on a family vacation in British Columbia this week.
"Spain, we grieve with you and denounce hate and violence in all of its forms. Canada will continue working with the international community to fight terrorism and build a world where we can all feel safe and secure.''
The attack happened shortly before 5:30 p.m. local time.
Spain, we grieve with you and denounce hate and violence in all of its forms.Prime Minister Justin Trudeau
Carles Puigdemont, president of Spain's Catalonia region, told a news conference two suspects had been arrested.
Spanish authorities say 13 people were confirmed dead and 80 were hurt, at least 15 of them seriously. The latest reports said 23 people were in hospital with moderate injuries and 43 more had been lightly injured.
The attack occurred just over a kilometre from Canada's consulate in Barcelona.
Global Affairs says Canadians in the Spanish city should monitor local media, including social media, for information and can contact the local consulate or the Emergency Watch and Response Centre in Ottawa for help.
Charles Mordret, a Quebecer who spends a lot of time in Barcelona, was not far from the area when he heard something had happened and started going towards it.
"People were coming in the opposite direction and I ended up going into a cafe,'' Mordret told La Presse canadienne.
Initial reports suggested one of the suspects may have been hiding in a bar just off the popular tourist strip but police later dismissed those reports.
Mordret said there were a lot of people on the street when it happened, but they cleared away.
"There are a lot of police officers. Every street is blocked off and at each corner there's a police cruiser. Helicopters are flying over the area. The streets are empty.''
Police cordoned off the area and metro stations in the neighbourhood have all been closed.
Las Ramblas is a tree-lined pedestrian mall lined with cafes and souvenir kiosks. There are two narrow service roads running along either side of the pedestrian mall.
Whoever did this wanted to cause a lot of damage.Charles Mordret
"Las Ramblas is bit like Sainte-Catherine Street in Montreal,'' said Mordret. "It's the main street, where the tourists are. Whoever did this wanted to cause a lot of damage.''
Politicians around the world, including U.S. President Donald Trump, expressed sadness.
Canadian Conservative Leader Andrew Scheer tweeted: "Our thoughts and prayers are with the victims. We stand together condemning these horrific acts of terrorism.''
NDP Leader Tom Mulcair called it terrible news: "We stand with Spain and all those impacted by this terror attack.''
Also on HuffPost: