Violent protests in Sao Paulo were quickly pushed to one side as drama switched to the football pitch.
Croatia took a shock lead when Marcelo scored an own goal in the 11th minute.
Neymar pulled Brazil level after 30 minutes, but Croatia were left in fury when Japanese referee Yuichi Nishimura pointed to the spot in the second half after Fred backed into Croatian defender Dejean Lovren and fell.
Barcelona golden boy Neymar, who was also booked, converted the penalty to put Brazil ahead and Chelsea midfielder Oscar scored a brilliant individual goal to seal the crucial vicotyr in Group A.
The five-time winners start the tournament as overwhelming favourites, seeking to heal decades of hurt after the humiliation of losing the final to Uruguay on home soil in 1950. But they made a nervous start in the Corinthians Arena.
The European side, who narrowly lost to the feted Selecao in the opening stages of the 2006 World, threatened to tear up the script.
The edgy home side, who had won their previous nine matches, struggled to find their rhythm after a rousing crowd rendition of the national anthem in the new stadium.
Mateo Kovacic went close for Croatia, missing the suspended Bayern Munich player Mario Mandzukic, with a right-footed strike and Ivica Olic headed just wide of Julio Cesar’s right post.
But the 18th-ranked side took the lead their early pressure deserved after 11 minutes as Olic, enjoying the space on the left, hit an inviting cross into the box.
Nikica Jelavic made contact and Brazilian defender Marcelo could not adjust his feet in time, watching in agony as the ball rolled into the net.
Undaunted, the crowd urged the home side on and Oscar went close with a left-footed strike from outside the box.
Neymar, tipped by many to cement his place as one of the game’s global superstars on home soil, pulled his side level with a strike from outside the area just before the half-hour, sending the crowd into raptures.
The No. 10 ran received the ball from Oscar before driving forward and shooting across Stipe Pletikosa with his left foot, the ball nestling just inside the post.
Brazil dominated possession for the remainder of the half but failed to create many clear-cut openings to add to their lead.
The second half began in scrappy fashion, with both sides struggling to establish a rhythm.
On the hour mark Croatian coach Niko Kovac brought on midfielder Marcelo Brozovic for Kovacic as they continued to frustrate their illustrious opponents, drawing whistles from the impatient crowd.
Minutes later coach Luiz Felipe Scolari, who led Brazil to World Cup glory in 2002, pulled off Paulinho to make way for Hernanes.
Scolari, who cranked up the pressure by declaring on the eve of the tournament “This is our World Cup”, then brought on Bernard to replace Hulk and seconds later Fred won the penalty that devastated Croatia. It was a harsh punishment for Lovren.
Pletikosa got a hand to Neymar’s shot but could not keep it out as watching President Dilma Rousseff cheered from the stands.
The crowd then vented its anger against the leader, battling to reverse widespread discontent over Brazil’s faltering economy and the record $11 billion it spent on the World Cup.
With time running out Brazil had to survive a few nervous moments and Cesar pulled off a save seconds before Oscar put the icing on the cake to send the crowd home happy.