The blind draw held in Nice, France, briefly saw Gibraltar paired up with their neighbours, and current European and world champions, Spain, in Group C.
But European football’s governing body UEFA had already announced in December that Gibraltar and Spain would be kept apart amid continuing political tensions over the territory’s sovereignty.
Gibraltar was immediately switched to Group D, with Scotland and the Republic of Ireland.
Gibraltar first applied for UEFA membership in 1999 but faced opposition from Spain, fearing setting a precedent for Basque and Catalan national teams.
The territory, which has a population of 29,000, became a full member of UEFA last year and will be competing in the qualifying round for the first time.
General secretary Gianni Infantino was quoted as saying: “Gibraltar is a full member and will participate in the draw on February 23, but it will not play against Spain. That was one of the criteria that was decided.”
Previously, in a similar situation, Armenia and Azerbaijan, who went to war between 1992 and 1994, were also kept apart in the qualifying round for Euro 2012.