The Merengues looked to be in trouble when Pandiani scored three goals in 19 minutes and Espanyol went into halftime with a 3-1 lead. But Real Madrid recovered in a wild second half on goals by captain Raul, substitute Jose Antonio Reyes and Franco-Argentine newcomer Gonzalo Higuain.
Higuain's winner after a one-two with Reyes in the 89th minute touched off wild celebrations at Madrid's Bernabeu Stadium.
Barca needed to win at home on Sunday to maintain its lead and looked to be command when Ronaldinho gave it an early lead from the penalty spot. Samuel Eto'o and Andres Iniesta came close to adding to Barcelona's lead, but Barca struggled in the second half after Lionel Messi and Ronaldinho were substituted.
Real Betis got back into the game in the second half, testing keeper Victor Valdes on several occasions before equalizing two minutes from time when Brazilian striker Rafael Sobis to the near post after breaking through the shaky Barcelona defense.