Sonny Kittel scored the winning goal for Raków in injury time at their home ground in Częstochowa on Wednesday night, the meczyki.pl website reported.
The Polish champions had taken a two-goal lead thanks to an own goal and a strike from Fabian Piasecki.
Redon Xhixha then scored twice for the Azerbaijani champions to make it 2-2, before Kittel, making his debut, won the game for Raków in the 91st minute.
To qualify for the Champions League group stage, Raków need to eliminate Qarabağ Agdam and two other rivals, Poland's PAP news agency reported.
Raków in May won the Polish premier league championship for the first time, while heavyweights Legia Warsaw, the most successful Polish football club in history, finished runners-up.
(pm)
Source: TVP Sport, uefa.com, meczyki.pl