The hosts rescued a victory from a seemingly inevitable defeat after Carlos Pouso's side soared into a two-goal lead with just 12 minutes remaining
Alain Arroyo gave the visitors the lead against the run of play midway through the first half, before Pablo Infante put his side into a seemingly unassailable advantage with just 15 minutes to spare.
However, Vladimir Weiss pulled one back for the hosts, and Mauricio Pochettino's men equalised soon after through Rui Fonte, before Joan Verdu sealed an unlikely victory.
The hosts started the game in fine form. They dominated possession of the ball, and although the Mirandes defence stood firm, they gradually began to craft chances.
Juan Forlin went close to putting his side in the lead, gathering the ball on the left wing, cutting in and sending a curling a shot wide of Nauzet Perez's goal, before Alvaro Vazquez capped a well-crafted move by shooting straight at the 26-year-old.
For much of the first half, Kiko Casilla had little to be concerned about. Alain Arroyo had a half-hearted appeal for a penalty turned down, before the visitors took a shock lead just before the half-hour mark.
A defensive error from Hector Moreno presented Arroyo with a run on goal, and he made no mistake, blasting the ball past Casilla to give his side the lead via the post.
Visibly shaken by falling behind, Espanyol created little for the rest of the half, and things went from bad to worse for the hosts when Alvaro Vazquez limped off shortly before half time.
Moments after the restart, Espanyol almost found themselves level. Romaric picked the ball up on the edge of the box and sent in a shot which cannoned off the post. The ball fell back to the Ivorian, but his second effort was gathered by the sprawling Perez.
Weiss forced another save from the goalkeeper with a powerful strike from the edge of the area, before Romaric's corner found Forlin, whose header was blocked on the line by the increasingly heroic goalkeeper.
At the other end, however, Mirandes continued to cause problems. Pablo Infante put an appetising ball across the face of goal that eluded everyone and had a credible appeal for a penalty turned down after Jordi Amat tugged him back.
In the end, it was third time lucky for Infante, as he pounced on a mistake from Amat and sent a delightful chip over the onrushing Casilla to give his side a two-goal lead with just 12 minutes remaining.
The second goal seemed to wake Espanyol up. The impressive Weiss rounded Perez and tapped into an empty net to give the hosts hope, and seconds later Rui Fonte slotted the ball home to get his side back on level terms.
A defensive lapse allowed Verdu to steamroller into the box and lash into the back of the net to rescue victory deep into stoppage time.
With two away goals, Mirandes will know that they are still in this tie, but will spend the journey home knowing that it could have been so much better.