Germany Protest: 200,000+ Against Racists
Rights groups organised the rally, as marchers held placards reading "Indivisible" and "United against racism".
The BBC's Jenny Hill in Berlin says even the organisers seemed surprised by the turnout.
Support for the anti-immigration AfD party has risen in recent years.
The Alternative for Germany entered parliament for the first time last year, becoming the biggest opposition party, and is expected to make a strong showing in elections in the southern state of Bavaria on Sunday.
Marchers walked through central Berlin, rallying at the Brandenburg Gate.
Many said they were defending human rights and tolerance, particularly of migrants.
"I'm worried that we are not there for the others, and that we just don't bother or care about loads of people who really need our help," said one demonstrator.
"Nobody just comes because they are bored."
One woman said: "There are so many people who believe they can abuse human rights and questions of equality and so on, and it's time to say no, there are other people who just want to be open and open-minded."
Gold flags and homemade banners glittered in the autumn sunshine as the march slowly moved across the city.
The mass protest - officially aimed at promoting an open society - was organised by hundreds of groups with different agendas and political affiliations.
But most of the participants were united by their concern about the influence of the far right on German politics and society.
Three years after Angela Merkel welcomed refugees to Germany, the politics of migration still divides opinion - and even now it has the power to bring citizens on to the streets.
Organisers of Saturday's rally say that more than 240,000 attended. Police said the number of participants was "in the low hundreds of thousands".
Theresa Hartmann, spokeswoman for the #unteilbar (indivisible) movement, said only 40,000 had been expected.
The march is partly as a response to the rise of the AfD, which has seen a particularly strong rise in support in eastern parts of Germany.
In August, far-right groups held protests in Chemnitz and other cities after the fatal stabbing of a German man blamed on migrants.
The arrival of more than a million migrants in the country in 2015 boosted support for the party, although immigration levels have since fallen sharply.