Brazil’s 67th-minute winner was fortuitous.
Alex Teixera’s weak shot ricocheted into the path of Kardec, who showed quick reactions to unleash a powerful volley from a tight angle.
Brazil had dominated possession, with Costa Rica’s Esteban Alvarado the busier of the two keepers.
But Los Ticos also had their chances and coach Ronald Gonzalez thought they had taken the lead following a Daniel Guzman free-kick, which Brazilian keeper Rafael tipped over the bar.
Brazil’s Paulo Henrique had a chance to break the deadlock after the interval but fired his effort straight at Alvarado.
Costa Rica rallied with both Guzman and Daniel Varela making a nuisance of themselves.
Ghana made the final after a 3-2 win over Hungary earlier on Tuesday.