ATHENS — Venturing into the most hostile territory in Europe, Chancellor Angela Merkel of Germany visited Athens on Tuesday, telling Greeks that she understood their suffering but urging the country to stay the course on reforms and budget cuts.

But even as Ms. Merkel said that she had come as a “good friend and a real partner,” not a “taskmaster or teacher to give grades,” the approximately 40,000 Greeks who took to the streets in protest (a rather modest number, by Greek standards) treated the visit as a provocation by the arch-nemesis in the euro crisis whose austerity medicine is obliterating the Greek middle class.

Some banners read “Don’t cry for us Mrs. Merkel” and “Merkel, you are not welcome here.” A small group of protesters burned a flag bearing the Nazi swastika, while a handful of protesters dressed in Nazi-style uniforms drew cheers of approval as they rode a small vehicle past a police cordon.

Some 7,000 police officers, many brought to the capital from the provinces for the day, were on standby, along with rooftop snipers.