Germany's budget surplus hit a post-reunification high of nearly 24bn euros (£20bn) in 2016 boosted by a higher tax take and increased employment.
This is the third year running that German government revenue has outstripped expenditure.
However, there was an increase in spending on housing and integrating refugees.
Under budget law, some of the surplus money will go into a fund for refugees.
Separately, official figures confirmed the economy grew by 1.9% last year, mainly because of higher spending by consumers and government.
The budget figures, published by Germany's Federal Statistical Office, showed that income was higher than spending in all areas of government - federal, state and local government, as well as social security.
The office said the main factors improving revenues were the large increase in income tax and property tax payments as well as the "good employment situation", which led to a "considerable growth" in social contributions.
In terms of expenditure, a big factor was increased spending by state and local governments on things such as accommodation for refugees, as well as payments to them for living expenses.
Germany has taken in more than a million migrants over the past two years, mainly from Africa and the Middle East.
The actual surplus figure of 23.7bn euros represents 0.8% of gross domestic product (GDP), meaning that Germany is still comfortably within the rule which requires European Union members to keep any budget deficit below 3% of GDP.
However, Chancellor Angela Merkel said: "If you look at the federal level alone, the surplus is rather small."
She said the government would increase spending on defence, as well as on domestic security and social improvements.
"At the same time, we don't want to take on new debt. So the room for manoeuvre is rather limited," she added.
The GDP figures showed that the German economy grew by 0.4% in the final quarter of 2016, primarily because of strong domestic demand.
As well as higher consumer spending, there was an increase in federal, state and local government expenditure.
Germany's economic strength has traditionally been bolstered by exports.
In the final quarter of last year, however "the development of foreign trade had a downward effect on growth", the Statistical Office said.
While exports of goods and services rose by 3.3% from a year earlier, imports increased by 4.5%.