Canada’s task to reach the IIHF 2017 World Junior Championship semifinals turned out to be a tough one, beating the Czech Republic 5-3 at the Bell Centre in Montreal on Monday.

Despite being wildly outshot 27-9 through two periods in this quarterfinal, the European side kept its North American opponent close, down just 3-2 heading into the second intermission. In the third period, three goals exchanged within three minutes and 19 seconds – two from Canada’s Julien Gauthier – gave the host nation some much-needed breathing room and ultimately, a trip to Wednesday’s semifinal game against Sweden.

RELATED: Canada 5-3 Russia | Canada 5-0 Slovakia | Canada 10-2 Latvia

Canada fell behind late in the first period with David Kase capitalizing on a fortunate bounce to give the Czech Republic a 1-0 lead with just 3:11 to intermission. A shot from the point that never reached the net, bounced off bodies including a referee to Kase’s stick. The puck eventually rested behind Connor Ingram in the Canadian net to the shock of Bell Centre that watched the host country outshoot the visitors 11-4 all for naught.

The second period brought out a much sharper Canadian side with Blake Speers scoring the equalizer at the 3:45 mark. Celebrating his 20th birthday, Speers tipped home a crisp centring pass from Mitchell Stephens to make it 1-1. A critical interception from Mathieu Joseph started the goal-scoring play, earning him the second assist on Speers’ first goal of the tournament.

Another first arrived less than four minutes later, this time Stephens getting his first goal of the 2017 World Juniors, wiring home the puck past Jakub Skarek in the Czech goal right from an Anthony Cirelli faceoff win to give Canada a 2-1 lead.

At this point the Czechs hadn’t registered a shot since Kase’s goal. That changed at 8:53 of the second period, along with the score line when Tomas Soustal knocked the puck along the boards from his own zone, skated up the ice, patiently held it past a sliding Canadian defenceman before snapping it through Ingram low for a 2-2 tie game.

The already eventful second period still had more to give with 6:28 to go and it was worth the wait for jittery Canada fans. A centring pass from behind the net by Stephens somehow slowly made it up to Thomas Chabot at the Czech blue line. The Canadian defenceman stickhandled through two players, veered past another pair of would-be blockers and fired the puck by Skarek’s blocker as Canada went to the dressing room up 3-2.

The final period started as wildly as the one previous with Gauthier giving Canada a 4-2 lead at 3:18 of the third.

That two-goal cushion became very much necessary as the Czechs came right back to cut the lead down by one at 4-3 through Simon Stransky just two minutes and 36 seconds later.

Incredibly, only 43 seconds after Stransky had renewed Czech hopes, Gauthier snuffed it out again with his second of the period and game (third of the tournament) for the 5-3 lead that finally held for Canada en route to the semifinals.

Stephens led Canada in scoring on Monday with his goal and two assists – his first points of the 2017 World Juniors. The shots were 41-19 in Canada’s favour.

Wednesday’s semifinal at the Bell Centre against Sweden will start at 7:30 p.m. ET. Sweden won its quarterfinal game against Slovakia 8-3 with Rasmus Asplund providing four helpers in the rout. Sweden finished first in its group ahead of the quarterfinals.

The other semifinal taking place at 3 p.m. ET on Wednesday at the same venue will feature Russia and the United States.

USA, Canada and Russia all came out of the same group before the knockout rounds. Canada’s previous victories were against Russia, Slovakia and Latvia before dropping a group game to the United States to set up the quarterfinal against the Czech Republic.

All World Juniors games are live on TSN.