Mr. Gauck told an audience of students and teachers that he came from a country “that has faced some of the same problems that China has to confront.”

East Germany “silenced its own people, locked them up and humiliated those who refused to comply with the will of the leaders,” he said. “And the entire system lacked proper legitimacy. Free, equal and secret public elections were not held. The result was a lack of credibility, which went hand in hand with a culture of distrust between the rulers and those they ruled.”

He criticized some countries’ insistence that they were unique and therefore beyond others’ judgment, an idea that Chinese leaders frequently put forward.

“For a long time, Germany claimed special cultural status — a sort of exceptionalism — according to which what was right for everyone needn’t necessarily apply to Germany. Ultimately, it took the cataclysm of Nazism and its defeat in the Second World War to make the Federal Republic of Germany open itself up to the basic principles” of Enlightenment philosophy, Mr. Gauck said: “inalienable human rights and the rule of law, separation of powers, representative democracy and popular sovereignty.”

He added, in another apparent reference to China today: “That moment made it clear that the human yearning for freedom cannot be kept down. That’s why individual liberties cannot be replaced by material goods or social status in the long term.”

Hua Chunying, a spokeswoman for the Chinese Ministry of Foreign Affairs, played down Mr. Gauck’s speech.

“As long as the two countries strengthen dialogue while respecting and treating each other equally, China and Germany can boost mutual trust and cooperation,” Ms. Hua said at a regular news briefing.