Canada did put the ball in the net in the 68th minute but Marcus Haber's goal was ruled offside. The Costa Ricans cleared the ball off the goalline in the 81st minute in a wild scramble after goalie Esteban Alvarado spilled the ball trying to corral a free kick.
The game ended with Canada sending everyone up for a last-ditch unsuccessful corner.
It was a harsh ending for the 103rd-ranked Canadian men, who played very well against No. 41 Costa Rica and lost just once in three games at the tournament. But the inability to convert chances left goalless Canada (0-1-2) fourth in Group B.
"It's quite a sombre dressing room," said Canadian defender David Edgar.
Jamaica (2-0-1) defeated El Salvador 1-0 in the earlier game at BMO Field to win Group B and move into the quarter-finals. Costa Rica (0-0-3) joined them as group runner-up.
El Salvador, which had the same record and minus-one goal difference as Canada, took third in the group on goals scored (one to Canada's zero). The Central Americans are likely to join the Canadians on the sidelines once Group C play is completed Wednesday.
The top two teams in the three groups plus the two best third-place team teams make the quarter-finals.
Canada came into the game needing a win to advance. Given the earlier result, anything other a 0-0 tie gave it a chance to finish third in the group but that would probably have not been enough, with Guatemala likely to add to its points total Wednesday against Cuba in Group C and join Group A's Panama (on three points) as the third-place finishers to advance.
The Canadians found themselves in a hole after tying El Salvador 0-0 in Carson, Calif., and dropping a 1-0 decision to Jamaica in Houston on a stoppage-time goal.
Canada has not scored in six consecutive Gold Cup games, dating back to a Dwayne De Rosario penalty June 14, 2011, against Panama.
In fact, Canada came into the game having not scored in open play at the CONCACAF championship, which covers North and Central America and the Caribbean, since July 10, 2009, in a 2-2 tie with Costa Rica.
Canada managed just two De Rosario penalties in 2011, when it went 1-1-1 and headed home after the first round. Two years later there was another early exit as Canada failed to score while compiling an 0-2-1 record that include a 1-0 loss to modest Martinique.
Costa Rica wasn't exactly red-hot either, having gone winless in its last four games at the tournament (0-2-2).
The game, which drew an announced crowd of 16,674, was Canada's first ever Gold Cup contest at home. It started as a wet one with the skies opening as the two team walked out to an enthusiastic crowd with support for both sides. The downpour soon relented, only to restart just before halftime.
The crowd included members of Canada's Pan American Games team. And behind the south stand, fans watched the Pan Am beach volleyball competition.
Captain Julian de Guzman had two early changes Tuesday, hammering a shot wide and then heading a ball punched away right back at the Costa Rican 'keeper.
At the other end, Karl W. Ouimette headed away a dangerous cross aimed at Costa Rica's Bryan Ruiz. David Ramirez, who plays in the French League for Evian, whipped a long shot just wide of the Canadian goal in the 18th minute.
Two minutes later, a long-rage Maxime Tissot free kick went through a crowd and deflected off the Costa Rican goalpost to safety. Haber, from close range, drove the ball straight at Alvarado in the 24th minute.
Canadian 'keeper Kenny Stamatopoulos had to make a fingertip save off Deyver Vega in first-half stoppage time. He was called on again in the second half, clawing away two well-placed shots from Johan Venegas.
The Canadians have had to play without influential midfielders Atiba Hutchinson and Will Johnson and defender Doneil Henry, who are injured or coming back from injury. No. 1 goalie Milan Borjan elected to stay with his Bulgarian club, which is facing Champions League qualifiers.
Canadian coach Benito Floro made four changes to the team that lost to Jamaica, two of which were enforced with Nik Ledgerwood and Samuel Piette both suspended due to yellow card accumulation.
Ouimette came in for Ledgerwood at fullback while Jonathan Osorio replaced Piette in midfield. Haber came in at forward for Cyle Larin and Tissot replaced Tesho Akindele on the wing.
It was a relatively young squad with the starting 11 totalling 309 caps, 82 of which belong to de Guzman.
Canada has not been beaten at BMO Field since a 2-0 loss to Peru in September 2010. The men have gone 6-0-5 there since and had won their last four games in Toronto.
The last time they lost in Canada was to Costa Rica, 1-0 at Edmonton's Commonwealth Stadium in May 2013.
The Canadians came into the game with a 5-7-7 career record against Costa Rica, which made it to the quarter-finals of the 2014 World Cup.
Follow @NeilMDavidson on Twitter