Surveys suggest Catalan voters would narrowly reject independence, though most favour holding a referendum.
On Friday, Catalonia regional government leader Carles Puigdemont decided to hold the vote later this year, in defiance of the government and contravening a ruling by Spain's Constitutional Court.
It is not clear if the referendum will go ahead.
Guardiola - who is revered in Catalonia for his footballing achievements - also demanded international help against "the abuses of an authoritarian state" at the rally.
Local authorities say that about 30,000 people attended, but a separatist source put the figure closer to 47,000.
The latest polls suggest that most Catalans support the holding of a referendum similar to the one held by Scotland in 2014 - the main difference being that the Scottish vote had the support of the British government.
Polls indicate a tight race, with 48.5% of respondents opposing independence, and 44.3% in favour.
In 2014, Catalonia held a non-binding vote in which people overwhelmingly backed independence. But on that occasion only about 2.3 million out of an electorate of about 5.4 million took part.
Catalonia is one of Spain's wealthiest areas and has its own distinctive language and customs.
Guardiola has spent most of his career with Barcelona, winning the club's first European Cup in 1992, and four La Liga titles. He has been captain and manager of the team - BBC