Real Sociedad dominated the early stages of the match, and Aritz Elustondo headed wide of the right post from a corner after three minutes.
Imanol Aggirretxe broke the deadlock in the 20th minute with a close-range finish after Alberto de la Bella's assist.
Rulli was dismissed as the last man and Gerard despatched the spot kick to level the scores.
Ten-man Sociedad came out strongly after the half-time break. Shots from Elustondo and Agirretze went off target.
On the hour mark, Gerard, looking for his second of the night, forced substitute goalkeeper Oier into a save with a long-range shot.
Espanyol took the lead in the 71st minute. when Roco headed into the top left corner from Hernan Perez's corner.
Just as the match looked like it was going to finish as a draw, Perez headed into the bottom right corner from Alvaro Gonzalez's corner.