The vote aimed at keeping out wild boar is controversial for several reasons.
Environmental campaigners doubt it will stop the animals entering Denmark, while others say Germany has no trace of the virus.
Some in Germany have condemned the move as gesture politics.
Work on constructing the fence is unlikely to start until autumn, after an assessment by Denmark’s environmental protection agency.
What will it look like?
The government says it will be 1.5m tall (almost 5ft) and 50cm deep, to prevent the boar burrowing beneath the fence.
The planned structure will follow the border between the north German state of Schleswig-Holstein and Jutland, from the Wadden Sea in the west to Flensburg Fjord in the east.
As Denmark is part of the Schengen passport-free group of EU states, roads through the area will not be affected by the fence.
Denmark’s minority government, backed up by the right-wing People’s Party and the opposition Social Democrats agreed to the fence, thought to cost around 80m Danish Kroner (€11m; £9m).
Will it work?
Critics have their doubts. Hans Kristensen, an expert on wild boar immigration, told Danish TV that wild boar did not inhabit the border area involved but did live to the east of where the fence was going to finish and were capable of swimming across the Flensburg fjord.
However, Environment Minister Jakob Ellemann-Jensen believes the risks of allowing African swine fever into the country are potentially catastrophic for Denmark’s billion-euro pig industry.
His opponents have pointed out that the nearest case of the virus to Denmark was in eastern Poland, a large distance away.
The biggest risk to the pork industry, opponents argue, is from contamination of vehicles used to transport pigs across borders and from the people involved in the trade.
Last month, the World Wildlife Fund warned the Danish prime minister and EU officials that the fence would harm other species besides wild boar, such as otters, wolves, foxes and deer.