Two late first half goals at either end looked to have ensured a draw for Wednesday at Birmingham.
But Blues substitute Jordan James had other ideas as the youngster climbed off the bench to score a late hit in the second half and give his side the win.
George Byers had put the Owls into a lead that lasted just over a minute before the Blues hit back through Juninho Bacuna and then James in the closing stages.
Overall, honours even was probably a fairer reflection. Before the drama in the dying embers of the opening period, Wednesday undoubtedly had the edge. Byers, Mallik Wilks and Josh Windass each had sights of goal without testing John Ruddy.
In terms of possession, the Owls assumed control, limiting Birmingham to occasional bursts upfield.
It nearly paid off seven minutes before the break when Barry Bannan delivered an unplayable cross into the path of the advancing Windass, whose glanced shot beat Ruddy and also the far post.
But Wednesday got their reward with the interval looming. Windass executed a wicked free kick from range that smashed against the upright and Byers was the first to react, diverting the ball into the unguarded goal.
The advantage, though, was short-lived as Birmingham immediately levelled. A corner was cleared only to the edge of the box, where Bacuna drilled a curling half volley flush past Cameron Dawson.
That gave the hosts a real boost going down the tunnel and they emerged with renewed vigour.
Jay Stansfield broke free down the right of the penalty area and Bambo Diaby came to the rescue with a well-timed block before Lee Buchanan clipped just wide from distance.
Blues kept up the pressure, with Siriki Dembele inches off target, brushing the side-netting with a low drive.
Wednesday were forced further and further back and Birmingham struck the decisive blow 10 minutes from time.
Dawson did well to keep out James as the substitute marched menacingly goalwards but could do nothing to prevent the same player picking up the rebound and tap into an empty net.
Wednesday: Dawson, Iorfa, Diaby, Ihiekwe, Famewo, Vaulks, Byers (Fletcher 81), Bannan, Wilks (Johnson 63), Musaba (Gussama 63), Windass (Cadamarteri 81)