An excavator operator found the 250-kilogram World War II bomb near the Karlsruhe-Basel railway line earlier on Friday.
All rail traffic on the busy main line was affected, including intercity trains, as experts examined the almost 80-centimetre-long device, Deutsche Bahn said.
Specialists from the Explosive Ordnance Disposal Service examined the device and came to the conclusion that it had to be detonated in a controlled manner.
The area around the site was therefore evacuated. About 5,000 citizens were reportedly affected. Around 11:15 pm (2215 GMT), the police announced that the device had been detonated.
Shortly after midnight, the Offenburg police announced via Twitter that after the successful detonation of the bomb, all closures had been lifted and residents were allowed to return to their houses and flats. The nearby A5 motorway was also reopened to traffic.
Even many decades after World War II, bombs continue to turn up during construction work. On average, about 1,300 tons of explosive ordnance are still found every year throughout Germany. Hundreds of unexploded bombs are defused.
Most of them date from the period between 1942 and 1945, when Germany was bombed from the air. It is unclear how much ammunition still lies underground.
According to the regional council of Stuttgart, 100,000 tons of dropped munitions fell in the state of Baden-Württemberg alone during the war, 10 to 15% of which did not detonate.
Most disposal operations proceed without complications. Sometimes buildings have to be cleared and roads closed.