The club moved quickly after it was confirmed on Thursday morning Rubi had paid up his release clause, believed to be around 900,000 euros (£812,000), which paved the way for his switch to Betis.
Rubi only arrived at Espanyol last summer, having guided Huesca into the top flight, and went on to take his new side to a seventh place finish in LaLiga and make the Europa League qualifiers.
Gallego has signed a two-year deal to step up into the top role following a long career within the youth and backroom set-up, taking over first-team duties following the departure of Quique Sanchez Flores in April 2018.
A club statement read: "Gallego is a coach who is committed to an attacking brand of football, tries to generate advantages and spaces from the possession without forgetting the defensive aspects.
"Energetic, with character and with a great vision to understand the game, the Suria coach is known for improving both the individual and collective performance of his teams."
Espanyol, meanwhile, had indicated Rubi left on good terms.
An earlier club statement read: "RCD Espanyol de Barcelona would like to reaffirm its personal and professional commitment with the up-to-now coach, who has been repeatedly shown support for his football philosophy, and wishes him good luck in his new post."