Lionel Messi helped Barcelona rebound from its loss at AC Milan by extending his league-record scoring run to 15 straight games in a 2-1 win over Sevilla on Saturday, three days before the Spanish leaders' key Copa del Rey clash with Real Madrid.
Madrid, meanwhile, needed Kaka to score his first goal in the Spanish league this season and cue Gonzalo Higuain's late winner to come back 2-1 at last-place Deportivo La Coruna.
The two archrivals will meet at Camp Nou Stadium on Tuesday with their Copa del Rey semifinal poised 1-1.
Barcelona's 11th win in 12 league home games kept it on course to recover the league title from Madrid, which is 16 points adrift. Atletico Madrid is 15 points behind Barcelona before it plays Espanyol on Sunday.
The first half at Camp Nou resembled Barcelona's disappointing 2-0 loss at Milan in the Champions League on Wednesday when the Catalan side couldn't turn its control into goals and its defense proved brittle.
Sevilla resisted well early on and its plan paid dividends when it struck through its first incursion into Barcelona's area from a free kick by Ivan Rakitic. Former Barcelona youth player Alberto Botia rose over his marker to turn Jorge "Coke'' Andujar's cross bouncing off the turf and beyond the reach of goalkeeper Victor Valdes.
Frustrated in its attempts to penetrate through the middle, Barcelona turned to the more traditional cross-and-volley route as Dani Alves picked out Villa strolling down the middle of the box to thump his lobbed pass home for the 52nd-minute equalizer.
Messi, who had forced one save from goalkeeper Antonio "Beto'' Bastos in the 22nd and missed with a pair of free kicks, put Barcelona ahead for good in the 60th when he used his left foot to slot in a pass from Cristian Tello after he had started the move by playing Tello wide.
It was Messi's league-leading 38th goal through 25 rounds and his 49th in all competitions this season.
Barcelona still struggled down the stretch and escaped with the victory only because Sevilla wasted its looks on goal.
Sevilla also faces a critical second leg in the cup on Wednesday when it must overturn a 2-1 loss to Atletico Madrid to reach the final.
After Tuesday's decisive Copa del Rey match, Madrid will host Barcelona in the Spanish league on Saturday.
Kaka was in Madrid's starting lineup only because coach Jose Mourinho rested several players for the looming match at Barcelona.
The move almost backfired when Ivan "Riki'' Sanchez took a well-struck goal in the 32nd to open for the hosts.
Desperate for a win in the home debut of Fernando Vazquez, its third coach in this strife-filled season, Deportivo outplayed Madrid in all facets during the first 45 minutes.
But after leaving Madrid without a shot between the posts until Jose Callejon's try in the final seconds of the first half, even Deportivo's best effort wasn't enough compared to Madrid's talent and two moments of inspiration from Kaka.
The former world player of the year came through late when Deportivo's legs had grown heavy to give Madrid just its second win at Riazor Stadium in 20 years.
Ronaldo went on for Madrid in the 57th, but it fell to the little-used Kaka to level in the 73rd with an exquisite long-range strike reminiscent of his glory days at Milan.
Kaka then played Ronaldo clear in the 88th for the Portugal forward to cross to the unmarked Higuain who just had to push the ball home to prevent Madrid from slipping up again on the road.
Madrid forward Angel Di Maria was sent off in stoppage time with back-to-back yellow cards for not maintaining the correct distance in a barrier during a free kick.
Elsewhere, Jonas scored a double to secure Valencia a 2-2 draw at 10-man Real Zaragoza and lift the team into fifth place, while Getafe rallied for a 3-1 win at relegation-threatened Mallorca.