Milan have not played in Europe's premier competition since 2014, but a comprehensive victory in Turin kept them third in the standings, three points clear of Juventus in fifth with two games to play.
After the break, the floodgates opened as Brahim Diaz scored a fine goal before Rebic helped himself to his first in the 67th minute.
Two more followed from the Croatian forward to give Milan the most comfortable of wins in what was expected to be a difficult match with local rivals Torino fighting for survival down the other end of the table.
Milan are level on 75 points with Atalanta, who also won on Wednesday, in second, with the pair due to meet on the final day. Torino are four points above the relegation zone and have a game in hand on their rivals for the drop.
Milan came into their second match in Turin in four days having beaten Juventus 3-0 at the weekend with the pressure on after Napoli leapfrogged Stefano Pioli's side into third with a 5-1 thrashing of Udinese on Tuesday.
With Juve and Atalanta winning on Wednesday, there was no room for manoeuvre, but after Hernandez superbly broke the deadlock, Milan never looked back.
"Two weeks ago everyone said we were half dead and out of the [top four] race, but now we have destiny in our hands," Pioli told Sky Sport Italia.
"By playing like this we have a better chance of achieving our goals and reaching the Champions League.
"Until you cross the finish line, you can't give up anything. We have done so much that we have to hold on for a week."
The rout was the first time Milan scored six or more goals in a Serie A away game since May 2001 against Inter Milan, and they have now won 15 away league games this season, equalling the best tally in a single Italian top-flight campaign.
Milan host Cagliari on Sunday, before a final-day showdown with Atalanta the following weekend.