FRANKFURT—The economic outlook for Europe and the world darkened after growth in Germany slowed sharply last year, hit by weaker exports to China and elsewhere, and softer demand at home.

While Europe’s largest economy probably narrowly avoided a recession at the end of last year, according to the country’s statistical agency, weaker German growth is ringing alarm bells across the continent, where swaths of companies are bound to the German export machine.

...