The match went into penalties after neither team managed to break the 1-1 deadlock after 90 minutes of normal time and 30 minutes of extra time, Poland's PAP news agency reported.
Czech striker Tomáš Pekhart scored the 1-0 goal for the Polish team in the 53rd minute of the game in Warsaw on Thursday night. Paulinho equalized for the visitors in the 71st.
Legia goalkeeper Kacper Tobiasz, who saved a penalty from Midtjylland's Steffan Gartenmann, was hailed the man of the match.
A week earlier, Legia drew 3-3 with Midtjylland in the first leg of their Europa Conference League round four qualifier in Herning, central Denmark.
The victory on aggregate over the two legs in the final qualifying round means the Warsaw club will play in the Europa Conference League for the first time, broadcaster TVP Sport reported.
Meanwhile, Polish football champions Raków Częstochowa will play in the group stage of the Europa League after failing to qualify for the Champions League at the hands of Danish side FC Copenhagen.
Raków in May won the Polish premier league championship for the first time, while Legia, the most successful Polish club in history, finished runners-up last season.
(gs)
Source: IAR, PAP, TVP Sport