World Cup winners Germany will be among Northern Ireland's opponents in the 2018 qualifiers.
Michael O'Neill's side will also take on the Czech Republic, Norway, Azerbaijan and San Marino in Group C.
The Republic of Ireland were drawn in Group D along with Wales, Serbia, Austria, Moldova and Georgia.
The top team from each group will qualify for the finals in Russia with the eight best second-placed teams going into the play-offs.
Northern Ireland were in Pot Three for Saturday's draw in St Petersburg and they had avoided Europe's top sides until Germany completed the group.
Germany will be firm favourites to top the group following their World Cup triumph in Brazil last year.
Northern Ireland could be battling for the play-off spot along with the Czech Republic and Norway.
"Germany are not unbeatable, they've shown that in their Euro 2016 group. They're struggling against Poland," said former Scotland player Pat Nevin.
"Northern Ireland had that brilliant run of form but it'll be tough for them. Czech Republic are a good side.
"There was a time Northern Ireland might slip up against the minnows but they won't have a problem with San Marino."
Irish FA chief executive Patrick Nelson said: "When Germany came out we just thought what a great competition this is going to be. Any group with Germany in it is going to be difficult, but it is going to be exciting."
The Republic were in Pot Four and they will be happy with the draw as they seek to make the finals for the first time since 2002.
"It's an interesting group. With all due respect to Wales you think fantastic, we haven't got Germany, Netherlands or Spain - no big boys," said former Republic striker John Aldridge.
"Austria are coming good - they go around in cycles. It's a cut-throat group, anything can happen."