The largest mass protests to hit Iraq and Lebanon in decades are posing a direct challenge to the influence Iran has gained in both countries as demonstrators seek to overturn the political order.

Late Sunday, protesters in the holy Shiite city of Karbala torched the Iranian consulate with Molotov cocktails, hauling an Iraqi flag up on the compound walls. Security forces killed three people when dispersing the crowd with live ammunition, according to Iraq’s human-rights commission.

Over...