Leon Goretzka scored his second goal in as many European matches to give Bayern the lead, the midfielder finishing a sumptuous passing move after 13 minutes as Hansi Flick's men rose to the challenge of playing lively opposition in front of a raucous crowd at RZD Arena.
Lokomotiv struggled to deal with the threat of Kingsley Coman and Thomas Muller on either flank, just as Atletico Madrid did in the 4-0 defeat against the German and European Champions six days earlier.
Bayern, who thrashed Eintracht Frankfurt 5-0 between their two opening Group A matches, looked set to drop points when Anton Miranchuk equalised 20 minutes from time.
But Kimmich kept a cool head to restore the visitors' lead, controlling Javi Martinez's pass before lashing home from outside the box.
Miranchuk's cross found Fedor Smolov unmarked after three minutes as the hosts started well but the striker headed straight into the arms of Manuel Neuer from close range.
Bayern reacted to the scare with a moment of quality befitting their billing as holders.
Corentin Tolisso chipped the ball out to Benjamin Pavard, who dinked a volleyed pass into the box where Goretzka headed down into the corner of the net, beating Guilherme at his near post.
Another Pavard volley almost teed up a second goal when he fed Kingsley Coman, who hit the post.
Lewandowski had a penalty decision overturned by VAR just past the hour, before Ze Luis broke clear with 70 minutes on the clock, crossing to the near post where Miranchuk slammed into the bottom-right corner from six yards.
But with 11 minutes left, Kimmich deftly controlled a Martinez pass before lashing the winner out of Guilherme's reach.
What does it mean? Flick's men survive unexpected scare
Lokomotiv went into the game on the back of a dismal 2-1 home defeat to Rotor Volgograd, who were bottom of the Russian Premier League, but they rattled Bayern with a dynamic performance.
Flick will have been pleased to see his men show the character required to grind out a win during a frantic end to the game.
While Muller was a handful on the Bayern right, the real problem for Lokomotiv was Pavard, who made two key passes and got an assist as he bombed forward to great effect.
No smiles for Smolov
Two shots on target were not enough for Smolov to open his Champions League goal account and it was Ze Luis and Miranchuk who caused Bayern the most problems.
Key Opta Facts
- Bayern have extended their winning run to 13 matches in the Champions League, the longest winning streak in European Cup/Champions League history, scoring 49 goals and conceding just nine in that period.
- Bayern remain unbeaten in their last 14 away European games (W11 D3) – in European Cup/Champions League history, only Manchester United have gone longer without defeat on the road (16 matches between Sep 2007 – Feb 2010).
- Goretzka has scored two goals in two Champions League games this season, having scored just one in his first 19 appearances in the competition.
- Kimmich has either scored (two) or assisted (five) seven of Bayern's last 15 goals in the Champions League.
Lokomotiv are back in action at Sochi in the Russian Premier League on Saturday before the visit of Atletico Madrid to Moscow next week, while Bayern are away at Cologne domestically prior to travelling to Salzburg in the Champions League.