Edinburgh will host Wasps in the European Challenge Cup quarter-finals after overcoming Bath.
Sam Underhill's brace of tries and one from Ben Spencer gave Bath a 19-15 half-time lead.
Emiliano Boffelli and Blair Kinghorn had crossed for Edinburgh in the opening period.
Pierre Schoeman's score turned the match back in favour of the hosts and Boffelli, Mark Bennett and Connor Boyle went over to make the game safe.
Boffelli also kicked nine points for Mike Blair's side, who will meet Wasps on the weekend of 6-8 May. Wasps defeated Biarritz 39-29 in France on Friday to secure their last-eight berth.
Edinburgh kicked off but were behind within two minutes. Underhill made the initial break after Jonathan Joseph put him through a hole. The attack was halted just short of the line but Bath recycled and Underhill got back to his feet to score from close range. Orlando Bailey converted.
Bailey's next kick, a penalty for a James Lang offside, was unsuccessful and Edinburgh were able to cut the gap.
Lang threw a deft pass out of the back, Kinghorn burst through the defensive line and Boffelli was put in to score. The Argentine's conversion attempt was wide but his first penalty put the hosts in front for the first time.
Bath had the chance to go back in front, and though Bailey's kick came back off a post, Underhill sneaked round a ruck to touch down again. Bailey's conversion attempt was wide.
Another delayed pass out of the back from Lang released Kinghorn and the fly-half effortlessly went through the gears to score under the posts, Boffelli adding the extras.
But again Edinburgh surrendered their advantage. Spencer darted over after a pocket of space emerged and the scrum-half himself converted.
Spencer's first kick of the second half, after Grant Gilchrist had infringed, was missed and the lead soon swung back in Edinburgh's favour.
The home side worked their way to the line and Marshall Sykes was stopped just short but the power of Schoeman was too much for Bath. Boffelli's conversion dipped perfectly between the posts.
Jaco van der Walt took over from Henry Immelman at full-back and the Scotland cap's superb pass put Boffelli in on the left for his second try. Another Boffelli conversion followed.
And, on the same side, Bennett burrowed his way past a clutch of Bath players to add his name to the list of scorers.
Edinburgh finished with 14 men after substitute Cameron Hutchison was sin-binned for a high tackle in the final 10 minutes but they got another try when Adam McBurney released Boyle to speed through.
Edinburgh head coach Mike Blair: "I said at half-time that I was frustrated, but excited. I'm frustrated because we gave Bath everything they wanted at the start of the game. I was excited because when we had the ball we executed.
"I'm happy because we showed a lot of resilience to come back. Blair at 10 is a huge run-pass threat. He was excellent. Schoeman was excellent - I think I'd be good if I had people chanting my name every time I touched the ball."
Edinburgh: Immelman, Moyano, Bennett, Lang, Boffelli, Kinghorn, Vellacott, Schoeman, McInally, Atalifo, Sykes, Gilchrist, Muncaster, Watson, Bradbury.
Replacements: Van Der Walt for Immelman (55), Hutchison for Lang (66), Pyrgos for Vellacott (63), Courtney for Schoeman (68), McBurney for McInally (77), Williams for Atalifo (55), Young for Sykes (61), Boyle for Watson (63). Sin Bin: Hutchison (74).
Bath: De Glanville, Rokoduguni, Joseph, Clark, Cokanasiga, Bailey, B Spencer, Morozov, Dunn, Stuart, W Spencer, Ewels, Bayliss, Underhill, Faletau.
Replacements: Cipriani for De Glanville (68), Butt for Cokanasiga (61), Simpson for B. Spencer (74), Cordwell for Morozov (68), Du Toit for Dunn (68), Rae for Stuart (68), Williams for W. Spencer (48), Richards for Underhill (68).
Ref: Ludovic Cayre (France).