Here is one way that should work, assuming each of the "random encounters" is achieved by a step event, and that all of the random combats are in the same step event chain.
In the same step event chain, create a Quest Stage event at the top of the chain (ie, before the combat events). In that Quest Stage event, set the "stage" setting to however many random encounters you want to occur before the dungeon is "cleared", +1. Select "Automatic (no question) from the "Accept" drop-down menu. Turn on the "Quest completed upon acceptance" button -- this will set the quest as "complete" (value 255) so that the "quest in progress" trigger will not longer be satisfied and the combat events will cease being activated. If you want further text or other events to occur when the dungeon is cleared (eg, a Gain Experience event), you can include those events in the "Chain on accept".
If the random combat events are found in different step event chains then you can either place the Quest Stage event (as above) that the top of a step event chain that happens on "every 1 step" in every zone where the combat events can occur, or duplicate the Quest Stage event at the top of each chain that includes one or more random combat events.
Hope that makes sense.