Sam Kerr's late volley sent Glasgow City into the last 32 of the Champions League at the expense of Polish champions GKS Gornik Leczna.
Jo Love headed City into a first-half lead at the Oriam in Edinburgh, but the Scots needed a second goal to qualify.
With five minutes left and Scott Booth's side poised to go out, Kerr volleyed past goalkeeper Anna Palinska to spark celebrations.
It means City top the group on a better head-to-head record.
A 1-0 win for City would have meant Anderlecht - who beat FC Martve 10-0 in the other group match - topped the section, while Gornik needed only a draw to finish first.
The draw for the last 32 takes place on Friday in Nyon, Switzerland. City will be seeded for their tie and will be away for the first leg on 12 or 13 September and at home on either 26 or 27 September.
City's patience pays off
The opener should have come in 31 minutes. Abbi Grant pounced on a lapse in the Gornik defence and bore down on goal, nipped round goalkeeper Palindka who slipped, but with the goal gaping her weak shot made it easy for Jolanta Siwinska to put a leg in and block.
But Grant made amends two minutes later. She got to the byeline and lobbed the ball for Love, who had an easy downwards header into the net.
Love had scored a 50-yard strike in Friday's 7-0 win over FC Martve. From an identical spot she took aim again, a slight deflection just taking it over as City searched for a second.
Lara Ivanusa hit the near post after being left alone in the box and Kerr's header was saved. The chances were coming.
City could not throw bodies forward with Gornik still threatening at the other end. Nothing would fall for the hosts until, finally, they got a break in the box.
Docherty drove in from the left, her cross deflected kindly into the path of Kerr whose thumping effort gave Palinska no chance.
Change of game plan
Love's goal forced Gornik to abandon their game plan of sitting in. Now they needed to come forward too. If neither side could find a goal they were both going out.
Emilia Zdunek shot wide and Ewelina Kamczyk's low effort troubled goalkeeper Lee Alexander, who then had to punch clear at a corner kick.
Alexander did well to palm away Dominika Grabowska's curling shot and Emilia Zdunek could not keep a shot down on the edge of the box.
Zdunek's low shot was blocked by Leanne Ross as Gornik came again, play continuing to rage from end to end, and Gabriela Grzywinska's effort had Alexander stretching.
Kerr's goal left them needing to score twice in five minutes. They pressed forward, but City held out.
'Comfortable & controlled'
Glasgow City head coach Scott Booth: "We had to fight really hard to win it.
"I thought we controlled large parts of the game. We were comfortable for large parts. But as the game is going on you're getting tired.
"I was just very happy and delighted for Sam [Kerr] that she got the second goal for us."