BERLIN—Germany's economy contracted in the fourth quarter, putting it at risk of a shallow recession at a time when euro-zone countries struggling with their debts are looking to the bloc's biggest economy to give the region a lift.

Germany's stagnation, after two years of strong growth, could fuel further international calls for the country to stimulate growth. Economists said Germany's nearly balanced budget and ability to borrow...