Goals by Robert Lewandowski and Gnabry put Bayern 2-0 up just after the break, but Cologne roared back with two goals in as many minutes by Anthony Modeste and Mark Uth.
Gnabry gave Julian Nagelsmann his first Bundesliga win as head coach by smashing the winner into the roof of the net 19 minutes before the whistle. Bayern seized control at the Allianz Arena when second-half replacement Jamal Musiala, 18, ghosted through the Cologne defence and squared for Lewandowski on 50 minutes.
The Poland star, who scored a record 41 goals in the Bundesliga last season, has already scored twice in as many league games in 2020/21. He has now scored in 12 consecutive Bundesliga games dating back to last season. Only Bayern legend Gerd Mueller, who died last Sunday aged 75, bettered the tally by netting in 16 straight league games.
Gnabry doubled the lead when he stabbed in a Thomas Mueller cross on 59 minutes. Cologne deserve credit for fighting back at 2-0 down and scored just a minute later. When Bayern defender Niklas Suele misjudged a cross, Modeste powered home his header. The French veteran then swung in a cross on Cologne's next attack which Uth stabbed home to level.
Gnabry restored Bayern's lead when he picked his spot from the edge of the area as his shot flew past Cologne 'keeper Timo Horn.