Wales are guaranteed a Celtic League finalist after Cardiff came from behind to beat Edinburgh 26-22 at Meadowbank.
Cardiff's effort means they will face Neath at the Gnoll in the weekend of January 3/4.
But had Edinburgh goal-kicker Brendan Laney's 80th-minute penalty-goal attempt not hit a post and bounced wide - the Blue and Blacks would have left Scotland empty handed.
As it was, when Cardiff fly-half Iestyn Harris kicked his fourth penalty goal in the 84th minute the victory was confirmed, and Cardiff still have a chance of Celtic League honours.
The first half was dominated by the home side, and indeed it was Edinburgh that had the first significant attack.
Fly-half Duncan Hodge passed to scrum-half Graeme Burns but, with the line begging, he spilled the ball.
But Edinburgh scored soon after with a Laney penalty goal after 10 minutes, and Scott Murray drove over for Edinburgh after 17 minutes to give the home side 8-0 lead advantage.
Edinburgh further extended their lead with two penalty goals from Laneuy in the 25th and 29th minutes.
Harris' successful penalty goal a minute later got Cardiff on the scoreboard, but Cardiff soon realised they had to step up their game as from the next play, Edinburgh fullback Derrick Lee cut inside Harris and outside Lewis to score a fine try despite the tackle of Craig Morgan. Laney missed the conversion, but Edinburgh were flying.
Harris' second penalty goal at the end of the first period reduced the deficit to 13 points, and took his Cardiff points tally to over 300. However, at 19-6 down at the half, Cardiff coach Dai Young - who utilised himself in the front row due to a number of injuries in the Cardiff squad - had to produce an inspirational team-talk.
And indeed, Cardiff ran out for the second half looking like a side with something to prove, playing into the wind seemed to help Harris' kicking, and the rugby league convert was beginning to assert his influence on the match.
Quality Cardiff play resulted in a third successful Harris penalty goal. And when Williams kicked a low drive to the corner.
The ball ricocheted off Edinburgh centre Ali Dickson and sat up for Williams to regather and score untouched under the posts, Cardiff were back in the game.
Harris' successful conversion cut the Gunners' margin to three points.
Edinburgh winger Simon Webster had the chance to extend his side's lead but failed to gather a Laney cross-kick in goal, and things began to get heated.
Baugh and Young threw punches in separate incidents, with referee Lewis sending Cardiff's player-coach and Edinburgh flanker Martin Leslie to the sin-bin.
A superb touch-finder from Harris put the visitors back on to attack, and scrum-half Ryan Powell was driven over to give Cardiff the lead for the first time in the match.
Laney's fourth penalty goal made 23-22 to Cardiff with eight minutes left on the clock, and the Kilted Kiwi had the chance to steal it on the 80-minute mark but - fortunately for Cardiff - his shot hit the very top of the righthand post and bounced away.
The other Celtic League semi-final is an all-Irish affair after Ulster sneaked home 20-17 against Glasgow in driving rain at Hughenden and Munster accounted for Connacht 33-3 at Musgrave Park.
The match at Thomond Park is a repeat of last season's semi-final, won 15-9 by Munster.
Edinburgh: Tries - S Murray, D Lee; Pens - B Laney 4.
Cardiff: Tries - R Williams, R Powell; Pens - I Harris 4; Cons - I Harris 2.
Halftime: Edinburgh 19-6.
Edinburgh: D Lee (C Sharman 79), C Joiner, B Laney, A Dickson, S Webster; D Hodge, G Burns; J Brannigan (A Jacobsen 63), D Hall, C Smith , N Hines, S Murray, T Blackadder (capt), M Leslie, S Taylor.
Cardiff: R Williams; N Walne, J Robinson, M Allen, C Morgan; I Harris, R Powell; P Rogers, A Lewis, D Young, H Senekal, J Tait (A Jones 73), E Lewis (T Payne 63-73), M Williams (capt), D Baugh.