Tuesday night's victory at the Santiago Bernabeu stadium left Madrid six points behind Barca, who host sixth-placed Celta Vigo on Wednesday (Thursday AEST).
It was Madrid's first game since they were eliminated 6-4 on aggregate by Bayern Munich in the quarter-finals of the Champions League. The team's last two La Liga matches had been a 1-1 home draw against Girona and a 2-1 loss at Mallorca.
"We have six games left," Madrid coach Alvaro Arbeloa said.
"The goal is to win all of them, regardless of what happens. Every game counts."
It was slow start for the hosts and part of the crowd jeered as Alaves had a few scoring chances early. There were some boos after the final whistle as well after the visitors scored late.
Mbappe broke the deadlock in the 30th minute with a deflected shot. The French superstar, the league's leading scorer with 24 goals, hadn't found the net in a league game since February.
Vinicius extended the lead with a long-range strike in the 50th. The Brazil forward hadn't scored in his last six games for club and country. He raised his hands in a gesture apparently apologising to the fans and there was some applause from the stands.
"Vinicius puts in a tremendous effort, carrying the team on his shoulders," Arbeloa added.
"We can't deny his attitude. He never hides. He feels a deep connection to the club and I'm happy when the fans reward him with applause."
Alaves, sitting one point above the relegation zone after one win in nine league matches, pulled one back in second-half added time.
Elsewhere, fifth-placed Real Betis won 3-2 at 11th-placed Girona.
Spain goalkeeper Unai Simon saved a penalty kick to help ninth-placed Athletic Bilbao hold on for a 1-0 home win against mid-table Osasuna, while struggling duo Mallorca and Valencia moved a point further away from the relegation zone after a 1-1 draw.