MADRID (AP)A ”bad night” by Real Madrid cost its unbeaten streak, its perfect away record and the Spanish league lead.

Madrid was far from its best in falling at Rayo Vallecano 3-2 on Monday, losing for the first time in the league and seeing its sixth-match winning run on the road come to an end. The setback dropped Carlo Ancelotti’s team to two points behind Barcelona.

”It was a bad night,” Ancelotti said. ”We didn’t play a good match.”

It was only Madrid’s second defeat in all competitions, after a loss at Leipzig in the group stage of the Champions League last month. Madrid won 15 of its first 19 games this season, with three draws.

”It hurts to lose but when you evaluate the first part of the season, we did well,” Ancelotti said. ”We are in good position in the league and advanced in the Champions League, which was our main objective.”

Madrid will face Liverpool in the round of 16 of the Champions League. It is eight points ahead of third-placed Atletico Madrid in the Spanish league. Madrid is the defending champion in both competitions.

Rayo was better during most of the match and earned only its second win against Madrid in the last 21 games against the city rival. The other was in 2019.

The hosts opened the scoring five minutes in at Vallecas Stadium with a shot from inside the area by Santi Comesana. Madrid rallied with Luka Modric converting a 37th-minute penalty kick awarded by video review and a 41st-minute header by Eder Militao.

Rayo equalized through Alvaro Garcia in the 44th and regained the lead with a penalty kick converted by Oscar Trejo in the 67th after VAR revealed a handball by Dani Carvajal inside the area.

Trejo’s shot from the spot was initially saved by Madrid goalkeeper Thibaut Courtois, but VAR intervened again and the penalty was retaken as Courtois apparently had his foot off the line and Carvajal entered the area before Trejo’s strike.

Rayo has won two in a row and extended its unbeaten run to five straight league matches. It moved to eighth.

”Our goal is to secure our place in the first division and we want to do that as soon as possible,” Rayo midfielder Alvaro Garcia said. ”Then we can start dreaming of achieving other things.”

Ancelotti could not count on striker Karim Benzema and defender Antonio Rudiger, who were not fully fit. Midfielder Toni Kroos also was out after being sent off in the previous round.

AP World Cup coverage: https://apnews.com/hub/world-cup and https://twitter.com/AP-Sports

Tales Azzoni on Twitter: http://twitter.com/tazzoni