While the terrible drama of Quebec's election night played itself out around a gunman who killed one person and injured another at the Parti Québécois' victory celebration, there was another tense moment most people didn't see.

It was how Jean Charest's Liberals nearly snatched victory from the jaws of defeat as the final votes were counted.

As we all know now, the PQ won a minority government. The final seat tally: PQ 54, Liberals 50, Coalition Avenir Québec 19 and Québec Solidaire 2.

All the major media organizations had confidently projected that outcome earlier on a fraction of the total results. But, should we really have been that confident?

CBC News held off projecting anything early because results were "too close to call." And in terms of popular vote, it was a virtual tie. The PQ was at 31.9 per cent to the Liberals' 31.2 per cent — much closer than many of the pollsters had previously reported.

And, with about 25 per cent of polls reporting from most ridings, there were 48 ridings where the margin between the leader and the second-place party was less than 50 votes.

Nevertheless, in terms of candidates leading and elected, the PQ had a commanding lead. They were about 20 seats ahead of the Liberals and beginning to look good to form a government.

A minority takes shape

What also appeared relatively certain was that the PQ was going to fall short of a majority. Just looking at the popular vote, it was far below what a party traditionally needs to win a majority. Only once in Quebec’s history has a party won a majority with less than 40 per cent of the popular vote — that was the Union Nationale, in 1944, needing just 36 per cent for a majority.

mi-cbc-control-room

The CBC's Montreal control room on election night last Tuesday. A close race that got closer made Quebec's election a hard one to call. (CBC)

With 18 ridings still to report a first result, we ran a graphic that calculates leading and elected, then adds in the seats that the PQ held when the National Assembly was dissolved that had yet to report any results. We call it the "Possible Majority Graphic." As CBC News anchor Debra Arbec explained, it was clear that with what the PQ had, and with sure PQ ridings still out there to report, there was a "gap" of seven seats to get to majority.

Meanwhile, as more results poured in, the PQ was maintaining a big lead on the Liberals in the on-screen tally of "leading and elected" ridings. In fact, they were just shy of that majority target of 63 seats.

So, with now about 35 per cent of polls in from most ridings, the PQ ahead in popular vote (albeit marginally), a 14-seat gap between the PQ and the Liberals (leading and elected), it was clear the CAQ wasn’t going to break through. CBC News projected a PQ government.

The key to our calculation was that while the margins in the close races were still small, the Liberals needed to flip all 14 to win — a hill too steep to climb.

At the same time, it was becoming clear that the four seats the PQ needed to get a majority were becoming unattainable. The margins in those ridings were too big to overcome. Once we saw that one of the four closest seats in which the PQ was in second place had built up a 500-plus vote margin, CBC News projected a PQ minority government.

At this point, in most ridings, we had about 60 per cent of the vote counted.

Soon after that we projected that Liberal leader Jean Charest would be defeated in Sherbrooke.

The next phase of our coverage was the leaders' speeches and reaction.

We all know well what happened when it came time for PQ Leader Pauline Marois to speak.

But behind the scenes during those moments of chaos and human tragedy, the results were creating drama of their own.

The Liberals were staging an astonishing comeback.

It ain't over 'til...

Of the 14 ridings they needed to flip to beat the PQ, they had managed to win 10. They were suddenly just four seats behind.

That meant if only two ridings where the Lberals were in second place to the PQ flipped, Charest would be the winner and leader of a minority Liberal government.

We could take small comfort that our minority government call was correct, but we could have been embarrassingly wrong about which party had won.

What were those two ridings and how close was it?

Saint-François was the closest. The PQ candidate beat the Liberal by 110 votes – a 0.3 per cent margin.

Abitibi-Est was the other. The PQ won it over the second-place Liberal by 777 votes – a 3.5 per cent margin.

As more of a measure of how volatile the final results really were, five of the 15 closest ridings had the CAQ finishing second. And, in 14 of those 15 ridings, the margin between first and second place was less than 1,000 votes.

It was that close.

Charest’s early election gamble very nearly paid off. He fell short by 897 votes.

As premier of even a minority Liberal government, with help from the CAQ, he could have dealt a stunning defeat to the PQ and Ms. Marois. Had she failed to win – when the Liberals were hurting, when polls were in her favour (68 per cent of Quebecers saying it was time for a change) and after surviving deep and troubling battles within her own party – her political future and perhaps that of her party would be in question.

A win is a win – even at 54 seats to 50.

Yes, this was a close call – not just for the political parties, but for the media organizations who try to project the results before all the votes are counted on election night.