Kylian Mbappe scored in each half as Madrid held on to beat Celta Vigo 3-2 on Sunday (Monday AEST) and remain four points behind their Catalan rivals going into next Sunday's match in Barcelona.
"La Liga is in Barcelona's hands, but we'll have more chances if we're able to win," Madrid coach Carlo Ancelotti said.
"It's a great opportunity. We're going to prepare well for Sunday's game, which I'm not saying will be decisive, but almost."
Arda Guler also scored for Madrid, who opened a 3-0 lead early in the second half but saw Celta get back into the game at the Santiago Bernabeu stadium.
Celta had a couple of great chances to complete their comeback, including a shot by Pablo Duran that stopped just short of the goal line after a deflection by Madrid goalkeeper Thibaut Courtois in the 78th minute. Courtois had to make a couple of saves near the end to secure the win.
"We did very well for an hour, we could have managed the lead a little better, but in the end it was a nice win," Ancelotti said.
Barcelona came from behind to defeat last-placed Valladolid 2-1 on Saturday, when coach Hansi Flick rested most of the team's regular starters ahead of their Champions League semi-final at Inter Milan on Tuesday. Barcelona and Inter drew 3-3 in the first leg.
Guler put Madrid ahead with a shot into the top corner in the 33rd minute, and Mbappe scored in the 39th and in a breakaway in the 48th. The France star hadn't scored in the league since March.
The match appeared under control until Javi RodrÃguez pulled the visitors closer in the 69th and Williot Swedberg scored Celta's second in the 76th minute.
A couple of minutes later, Duran's shot agonisingly stopped just in front of the goal line after the ball picked up some backspin as it struck Courtois.
Celta, coming off a 3-0 win over Villarreal, stayed in seventh place.
It was the fourth straight league win for Madrid.
Elsewhere, the Basque Country derby between Athletic Bilbao and hosts Real Sociedad ended in a 0-0 draw.
Athletic are three points ahead of fifth-placed Villarreal and six points behind third-placed Atletico Madrid.
Athletic were coming off a 3-0 home loss to Manchester United in the first leg of the Europa League semi-finals.
Mid-table Sociedad are winless in four matches.
Also on Sunday, 15th-placed Sevilla drew 2-2 with second-to-last Leganes, and sixth-placed Real Betis beat 14th-placed Espanyol 2-1.