Frank-Walter Steinmeier, Germany's foreign minister, said on Tuesday that the two men, who had been abducted on January 24 outside their workplace in the industrial town of Baiji, 180km north of Baghdad, were freed without warning and appeared to be unharmed.
"I am very pleased to inform you that the two kidnapped men from Leipzig, Rene Braeunlich and Thomas Nitzschke, have been freed today," Steinmeier said in a statement.
He addedd the men, being looked after in Germany's embassy in Baghdad, were expected to return home on Wednesday.
"After spending more than three months under inhumane conditions they are in German care," added Steinmeier, who was on an official visit to Chile.
Reinhard Silberberg, the German foreign ministry's state secretary in charge of the hostage task force, told a news conference he could not provide any details about their release.
"I ask for your understanding that the government can give no further details about this case ... or about the circumstances of the release," said Silberberg, who walked away without answering questions after the brief statement.
"I am very pleased to inform you that the two kidnapped men from Leipzig, Rene Braeunlich and Thomas Nitzschke, have been freed today"
Frank-Walter Steinmeier, Germany's foreign minister
Another German hostage, archaeologist Susanne Osthoff, was freed in December after being held hostage in Iraq for three weeks.
German media have quoted unidentified diplomats as saying Berlin paid the kidnappers $5 million for her release.
The German government is known to have paid ransoms for hostages in the past, but refused to comment on whether it did so for Osthoff.
More than 200 foreigners and thousands of Iraqis have been kidnapped since the US-led invasion of Iraq in 2003. Most foreign hostages have been released.