President Hassan Rouhani said Wednesday Iran would do whatever it takes to protect revered Shiite shrines in Iraq against Sunni militants fighting the Baghdad government.