Local news agencies showed family members shouting at the president and hitting his car as he visited the site in the northern Golestan province, where at least 26 people were killed by an explosion on Wednesday.
"The entire Iranian nation shares the sorrow of families of those killed in the Zemestan Yort mine accident," Rouhani said according to the government's website.
"Those responsible and anyone who had a fault in the incident must be found and dealt with accordingly, without any exceptions," said Rouhani, who is standing for re-election on May 19.
The accident is thought to have been caused by concentrated methane gas that was triggered when workers tried to jump-start an engine.
More From This Section
Workers and families are angry over poor safety conditions, but also over delayed wages -- a common problem in factories and industrial enterprises across the country due to the struggling economy.
Labour Minister Ali Rabii travelled 1,400 metres deep into the mine earlier, where rescue teams have been trying to unblock the collapsed tunnel.
"We are all responsible in this incident," said Rouhani, calling for tighter regulations in the mining sector.