Athletic had won 16 and drawn three of 19 games in front of their own fans since their last home defeat.
Real Madrid stretched their lead at the top of LaLiga to five points thanks to a 2-1 victory away to Athletic Bilbao at San Mames.
Goals from Karim Benzema and Casemiro, either side of an Aritz Aduriz header, were enough to settle a hard-fought encounter at San Mames and put the pressure on Barcelona ahead of their meeting with Valencia on Sunday.
Athletic had won 16 and drawn three of 19 games in front of their own fans since their last home defeat, which came against Barca in August, and were bright and industrious in the early stages.
They were given a warning sign of Madrid's threat on the counter when Cristiano Ronaldo had a goal disallowed in the early stages.
Ronaldo exploited the home side's high defensive line to better effect in the 25th minute, though, as he raced through before crossing for Benzema to side-foot home his 16th goal of the season.
Ernesto Valverde's side enjoyed plenty of possession without threatening Madrid's goal too often, but Aduriz capitalised on a rare moment of slack defending to head his team level midway through the second half.
But Casemiro proved Madrid's unlikely hero just three minutes later, tapping in from close range after being left unmarked at a corner to secure Madrid's 13th win in 15 league meetings with the Basque side.
The result ensures that Zinedine Zidane's team will be top of the table heading into the international break and leaves Barca needing a good result at Mestalla to keep the pressure on in the title race.
Athletic had Madrid penned back into their own half in a dominant opening 10 minutes, although Keylor Navas was forced to make only one save of note to keep out a Raul Garcia volley.
Madrid had the ball in the net with their first attack of the match but Ronaldo was offside when he tapped in Dani Carvajal's low cross from the right.
Yeray Alvarez prodded a glorious chance wide following Garcia's knockdown but Madrid continued to look dangerous on the break, and Kepa was forced into a one-handed stop low to his left after Ronaldo was played in by Benzema.
It was a warning sign Athletic failed to heed, though, with the visitors' attacking duo combining in ruthless fashion to give them the lead after 25 minutes. Ronaldo timed his run to escape the offside trap and reach Casemiro's pass, and his low cross from the left was guided into Kepa's bottom-right corner by the Benzema.
Madrid looked content to sit back and try to hit Athletic on the break, with Gareth Bale spurning one half-chance just after half-time, but Navas was called on to make a fine low save to deny Inaki Williams after Oscar de Marcos picked him out on the edge of the six-yard box.
But the lively Williams played a pivotal role in Athletic's equaliser with 25 minutes to play, as his deep cross from the right was headed back to the six-yard box by Raul Garcia, allowing the unmarked Aduriz to nod the ball into the net.
The jubilation around San Mames lasted only three minutes, though. Ronaldo rose highest to glance a corner into the feet of the unchallenged Casemiro, who was free to tap home from two yards out after Kepa had already gone to ground.
Marcelo fired over the crossbar with the goal gaping after another defensive mix-up in the home penalty area and Navas preserved Madrid's lead when Williams again escaped down the right and drilled a shot towards the near post.
Zidane withdrew Ronaldo for an extra midfielder in the shape of Isco in the closing stages, and Madrid stayed impressively compact to see out what could prove to be a crucial victory in their quest for a first league title since 2012.