An estimated 45,000 people packed into the capital's Plaza de Colon, many of them waving Spanish flags and signs reading "Stop Sanchez" and "For a united Spain, elections now!"
The rally was organized by the conservative opposition Popular Party (PP) and the center-right Citizens Party, with backing from the far-right party Vox.
"The time of Sanchez's government is over," PP leader Pablo Casado told reporters at the start of the march. His opposition party is firmly against the prime minister's decision to tackle political tensions in northeastern Catalonia by negotiating with pro-independence parties.
Read more: Catalan leader pressures Spain to recognize independence
Key budget vote
Sanchez came to power in June, inheriting the Catalan independence crisis from former Prime Minister Mariano Rajoy of the conservative PP. The Socialist leader holds just a quarter of the seats in parliament and relies on backing from anti-austerity party Podemos, Catalan nationalists and other small parties to pass laws. His minority government last week agreed to allow an independent rapporteur — as requested by Catalan separatists — to attend future talks with pro-independence parties. That prompted an outcry from the opposition, which accused Sanchez of giving in to pressure from the separatists, whose votes he will need to pass a crucial budget plan next week.
However, the government broke off the negotiations on Friday when Vice President Carmen Calvo said the separatists had refused to back down from their demand for an independence referendum.
If Sanchez fails to secure enough votes to pass the 2019 national budget, he may be forced to call snap polls. Opinion polls suggest the PP, Citizens Party and Vox would win a majority of seats in parliament if early elections were held.
Read more: How dangerous is Spain's far-right Vox party?
Tensions high ahead of trialSunday's protest comes as 12 jailed Catalan leaders prepare to go on trial at the Supreme Court in Madrid on Tuesday.
They are facing up to 25 years in prison on charges of rebellion for their role in a failed secession bid from Spain in 2017.
The highly sensitive trial is expected to last for three months and there are concerns it could reignite tensions surrounding the fate of Catalonia.
DW editors send out a selection of the day's hard news and quality feature journalism. You can sign up to receive it here.