The only way to prevent this from happening is to prevent the crowd from massing in front of an exit or entry, the correct crowd control strategy is to funnel the crowd between barriers until it is reduced down to single lines of individuals. This is not a perfect strategy, but if the "funnel" is long enough it's quite effective.
Any venue which routinely experiences crowds seeking entry (for example sporting and entertainment events) has a security staff and procedures in place to deal with this even if the crowds are impatient or unruly, the problem here is either the crowd was unanticipated or that the venue was unfamiliar with crowd control.
And when the people in back can't see what's happening in front, stuff like this happens.