The combined budgets of the German government, regional states, municipal authorities and welfare system showed an overall surplus of €18 billion last year, the federal statistics office Destatis calculated in a statement.
It was the first time since unification in 1990 that Germany's public finances have been in the black. The surplus represented 0.6 percent of the country's overall gross domestic product (GDP) of €2.904 trillion, Destatis said.
In 2013, Germany had achieved a balanced budget in its public finances.
At the same time, Destatis calculated that German growth picked up in the fourth quarter of last year, with GDP expanding by 0.7 percent.
The statistics office said that Germany's financial surplus last year resulted from the difference between revenues of €1.294 trillion and expenditure of €1.276 trillion.
The government budget alone showed a surplus of €11.4 billion, compared with a deficit of €4.5 billion a year earlier.
The regional states' finances also swung to a surplus of €1.9 billion in 2014 from a deficit of €2.8 billion in 2013.
The municipal authorities turned in a surplus of €1.3 billion and the welfare budget showed a surplus of €3.4 billion, Destatis said.
Under eurozone rules, member states are not allowed to run up public deficits in excess of 3.0 percent of GDP and are obliged to bring their budgets into balance or surplus in the medium term.
Robust domestic demand
Confirming a preliminary estimate published earlier this month, the statistics office said that GDP growth of 0.7 percent in the fourth quarter was driven primarily by robust domestic demand.
Following a strong start to the year, when GDP grew by 0.8 percent in the first three months, the German economy subsequently lost momentum due to the uncertainty surrounding the Ukraine crisis and other geopolitical risks.
GDP actually shrank by 0.1 percent in the second quarter and showed only meagre growth of 0.1 percent in the third quarter.
But domestic demand helped growth pick up again at the end of the year, with consumer spending rising by 0.8 percent and public spending by 0.2 percent, Destatis said. Investment also increased and exports rose by 1.3 percent.
Analysts welcomed the latest set of positive data for Europe's biggest economy.
"Looking ahead, we expect more positive news from the German economy, in line with the brightening trend in soft data - such as the sentiment indicators - and hard data," said Natixis economist Johannes Gareis.
The expert said he was particularly cheered by the rebound in business investment in the fourth quarter.
"As the fundamentals are good and the uncertainty seems to fade, we think that the recovery in business investment is likely to strengthen in the course of 2015," Gareis said.
In addition, household consumption should remain an important pillar of Germany's growth, the expert said.
"Household confidence is very buoyant and households' real income is bolstered by solid wage increases due to a robust labour market and low inflation, which all bodes well for private consumption growth," he said.
Benchmark wage deal
Earlier on Tuesday, Germany's powerful metalworkers' union, IG Metall, reached agreement with management for a 3.4-percent wage increase for the sector which is expected to act as a benchmark for much of the rest of German industry.
BayernLB economist Stefan Kipar said the latest data "show that the German economy has gained a lot of momentum at the end of last year and the outlook for the current year is equally positive."
"In an environment of low interest rates and above-inflation wage increases, consumption will continue to provide a lot of impulses for the German economy in 2015," Kipar said.
It remained to be seen to what extent the Greek debt crisis and other geopolitical risks would weigh on German exports, he said.
"But we expect the fallout to be limited," Kipar added.