Iranian security forces struggled to contain the boldest challenge to the clerical leadership since unrest in 2009.