Michael Smith had given Northern Ireland a shock early lead on Wednesday (AEDT), however Germany hit back in emphatic fashion with Leon Goretzka also grabbing a brace for the hosts before Julian Brandt's injury-time strike.
Gnabry's treble took his tally for 2019-2020 to 14 goals for club and country as his fine start to the campaign continued with another clinical display.
Having finished third in the group, Northern Ireland - on whom the result was harsh - must now wait for Saturday's (AEDT) draw to discover who it will face in the Euro 2020 qualifying play-offs.
Germany was stunned in the seventh minute when Toni Kroos could only head George Saville's cross to the edge of his own area and Smith unleashed a stunning low strike into the bottom-left corner beyond the reach of Marc-Andre ter Stegen.
Germany was almost level five minutes later after Ilkay Gundogan struck the post and soon it had its goal as Gnabry controlled Jonas Hector's cross from the left before swivelling and firing clinically into the far corner from 12 yards out.
Hector was again the provider two minutes before the interval as Germany turned the contest on its head.
His cross somehow evaded a crowd of bodies before the onrushing Goretzka made sufficient contact to send the ball agonisingly past Northern Ireland goalkeeper Bailey Peacock-Farrell and in off the post.
Within two minutes of the restart, Germany had a third as Lukas Klostermann found Gnabry, who again rifled home in clinical fashion.
Gnabry was celebrating his hat-trick just on the hour when he held off Tom Flanagan before drilling a low shot inside the far post.
Germany added further gloss, with Goretzka firing in from the edge of the area in the 72nd minute before Brandt struck from the left side of the box in added time.