The miners were among a group of around 20 that were in pit when a shaft they were working on collapsed on October 5.
While 14 escaped as the shaft collapsed, six were trapped. One of the miners died during the more than month-long incarceration underground.
The remaining five were rescued on Sunday and are reportedly in a serious condition in hospital.
"The miners were very weak," Minister of Energy and Mines spokeswoman Badra Masoud said, adding they had been trapped some 100 metres underground.
More From This Section
"We were around 20 in the pit that collapsed, some of our colleagues made it out, but six remained trapped underground," survivor Chacha Wambura told state-owned television late yesterday.
"We survived by eating cockroaches, frogs and other insects as well as drinking dirty water that seeped in from above."
The local miners were digging for gold in the northwestern Shinyanga region when the shaft collapsed behind them, blocking them deep underground.
"Batteries of the torches and flashlights ran out and we ended up in a cave that we earlier used as a store for our tools," Wambura said.
Tanzanian newspaper The Citizen said the mining ministry described the rescue as "a miracle" while local officials were initially in disbelief the miners could have been freed safely after so long underground.
Tanzania is Africa's fourth largest gold producer, and the precious metal is one of the top foreign exchange earners for the country.