All the levels of government – federal, regional and municipal – combined took in €18.3 billion more than they spent, data from federal statistics authority Destatis showed.
Government revenue from taxes, social contributions and other sources amounted to €724 billion, a 4.3-percent increase on the same period in 2016.
Spending grew at the same pace, adding 4.3 percent to reach €705 billion.
With gross domestic product in the first half of the year at €1.6 trillions, the budget surplus stood at around 1.1 percent of GDP.
“Federal, regional and municipal budgets continued to benefit from favourable developments in the labour market and in the economy, as well as a restrained spending policy,” Destatis commented.
But the authority cautioned that the first-half figures should not be extrapolated to the whole year, as one-off events can have a big impact on government finances.
Allies, neighbours and international institutions frequently criticise Germany for its reluctance to increase investments at home, which some argue could help reduce its mammoth trade surpluses.
The government took in almost €24 billion more than it spent over the full year in 2016.
In a separate release, the statisticians confirmed that German gross domestic product had grown 0.6 percent in the second quarter, a slight slowdown from the first three months' 0.7-percent expansion.
Big increases in both household and state spending between April and June as well as higher investments in capital goods and construction meant that domestic forces were the most important for growth.
Meanwhile, imports expanded faster than exports, at 1.7 percent compared with 0.7 percent according to preliminary figures, slightly weakening the contribution to GDP growth from the balance of trade.
So far, strong growth in the first half has not prompted Berlin to revise its full-year GDP forecast upwards from a cautious 1.5-percent prediction.