While standards of living have improved for millions, many services remain poor and will be the focal point of unrest in 2014

The night of 30 June was one of intense drama in Rio de Janeiro. Inside the newly refurbished Maracanã stadium, still slick with plaster dust, a gladiatorial atmosphere turned to celebration as Neymar scored Brazil's second goal in a 3-0 victory over Spain in the Confederations Cup final, on the cusp of half-time.

This dramatic game could have been the perfect curtain-raiser for the 2014 World Cup, were it not for the scenes outside the stadium, where thousands of protesters faced off against police in riot gear, the air thick with teargas and insults. Last Tuesday, the story was repeated. As TV Globo showed the 2-0 victory over Poland that clinched England's place in the finals, 10,000 people joined a protest in central Rio in support of striking teachers, a few miles from the Maracanã.

As teachers began to drift home, the sound of carnival drums was replaced by the thump of percussion grenades and the hiss of exploding teargas canisters as hundreds of black-clad youths, known as the "Black Bloc" after the anarchist demonstration tactics they adhere to, began battling outnumbered police.

Protesters advanced across the square through a haze of teargas, using corrugated iron sheets as cover and throwing rocks and fireworks. At one point police retreated, more than once they threw rocks back. Demonstrators trashed bank foyers and cash machines, phone booths and a mobile phone shop. Hundreds were detained.

This was the second teachers' demonstration in a week to end in violence. As in June, when hundreds of thousands took to the streets, demanding better health, transport and education services, or an end to corruption, one rallying cry was: "There won't be any World Cup." Reading news reports the next day, England fans planning 2014 trips must have wondered: whatever happened to Brazil's World Cup party?

Brazil is the B in the Brics –Brazil, Russia, India, China and South Africa – the country that, under popular President Luiz Inácio Lula da Silva, saw a decade of phenomenal social advances in which 40 million people escaped from poverty and joined a new, emerging lower middle class – known officially as "Class C". Many were able to buy their first mobile phone, computer and car, creating a new army of consumers. What are they protesting about?

It is not just services. Paradoxically, even government experts admit that this social improvement is behind the protests. "These protests have a positive relation to inequality. Inequality fell and protests grew," said Marcelo Neri, acting minister at the government secretariat for strategic subjects, president of the Institute of Applied Economic Research and an acknowledged Class C expert.

"There was a growth of people's income above the growth of GDP. Last year it was 7.9%, and the GDP grew 0.9%," Neri said. "So life inside people's houses is getting better, and outside is not getting better at the same velocity."

Class C now makes up more than half of the Brazilian population. The demographic group once marginalised as "the poor" now plays a confident and central role in Brazilian culture, with its own pop stars, like singer Anitta, and even a hit soap opera on Globo called Brazil Avenue, which for the first time celebrated its brash, colourful suburban style on primetime television and was a nationwide hit.

"Globo soap operas used to be a magic eye, for the poorer people to see the rich," said Antonio Prata, one of the soap's scriptwriters. "Brazil Avenue did the opposite … Class C didn't want to see the rich, they wanted to see themselves reflected."

But what Class C members can buy in terms of consumer goods – often on credit – does not make up for the failing social services around them, particularly in health, education, sanitation and transport. Many live in tiny breezeblock houses, in endless, gritty suburbs, hours away from city centres by bus. Transport was the spark that lit June's protests: an increase in bus fares in São Paulo and Rio.

"These Brazilians are consumers without citizenship, without civil rights. They are not citizens," said celebrated novelist Milton Hatoum. "There is consumerism but no citizenship. The schools for their children are terrible. Education is terrible. Often there is no sanitation."

The World Cup will go ahead: the government is too far down the line for it not to. But Brazilians of all backgrounds are agreed that there will be more protests. World Cup costs are one of the triggers.

"In the last year, Brazil spent twice as much on refurbishing and constructing stadiums for the World Cup as on basic sanitation," said the film director Walter Salles, who made The Motorcycle Diaries and On The Road.

He noted that among the stadiums being built and refurbished at a cost of 8bn real (£2.27bn), among myriad accusations of corruption, are "white elephants" such as those in Brasília and Manaus – cities whose football teams play in lower leagues.

Protesters demand "Fifa standard" health, education and transport. "Knowing the terrible conditions offered in those areas by the Brazilian state, the claims are fully justified," said Salles. Hatoum concurs. "Next year there will be gigantic demonstrations, before and during the World Cup," he said. "The construction of monumental stadiums was an aberration."

The Amazônia arena, built in Hatoum's native Manaus, deep in the Amazon jungle, has cost 600m real – but the local team play to crowds of a few hundred. According to 2012 government figures, 20.2% of houses in Manaus do not have proper plumbing. Nationwide, 15.1% of Brazilian children up to four years old live in areas where sewage runs outdoors.

Brazil spends heavily on education – 18.1% of government expenditure in 2010, according to the World Bank – but achieves little. According to recent OECD figures, Brazil's education spending rose to 5.6% of GDP in 2010 from 3.5% in 2000 – but the number of those aged 15-19 in full-time education in 2011 was only 77% (the OECD average is 84%). Teachers' salaries are low – hence the strike – and public schools desperately lack resources. "We had a distribution of wealth, but not in a way that was thought. Many people got money who did not have education," said Papoula de Almeida, 42, a training consultant. "It is only private schools that function here."

Public health services are intermittent. In some areas, such as central Rio, free health centres function well, but in outlying, poorer suburbs or favelas (shanty towns), they are pitifully lacking. Brazil spent $1,000 per capita on health in 2011, 8.9% of its GDP, according to the World Health Organisation. But even lower-middle-class Brazilians spend money on private health plans.

"If you go to the health centre in my district, you will see that there is much to be improved," said Criolo, an MTV award-winning rapper from the sprawling São Paulo favela of Grajaú. "Imagine a first-world country. People don't stop demanding things. So imagine ours, this fight to improve everything."

Growth in the Brazilian economy has also stalled. In 2010, it hit 7.5%. The Economist celebrated in November 2009 with a cover depicting Rio's famous Christ statue rising like a rocket and the headline "Brazil takes off". Last year the GDP grew just 0.9%. In September, the Economist featured the same statue as a nose-diving rocket and the headline: "Has Brazil blown it?"

World Cup 2014 host cities graphic Photograph: Observer Graphics

Tony Volpon at Nomura Securities in New York, one of the most respected analysts on the Brazilian economy, believes the country is at a crossroads, having relied too long on high prices the Chinese paid for exports such as iron ore and unsustainable, credit-funded consumer spending by Class C.

"There was a very long and important cycle in commodity prices driven by China. This basically made Brazil and other countries wealthier because you are selling what you produce for more," he said. "Brazil unfortunately took that new wealth and decided to consume a great proportion and not invest. That consumption made Brazil a very expensive place."

Brazil has major infrastructure problems – there are virtually no trains, many major roads are crumbling, airports chaotic and overcrowded, mobile phone and internet signals fail regularly. All this frustrates the population, who are increasingly in debt, anyway. "The consumers have [lost money] because you had a party and you consumed a lot and now they're leveraged," said Volpon.

But Brazil is still close to full employment. And despite its problems, people still have more money than ever before. And as Marcelo Neri notes, many of the protesters, particularly in São Paulo, are from middle-class backgrounds. "Even in June, they reached a small part of the population, less than 2%," he said. Neri argues that if Brazil play well, as in the Confederations Cup, protests will be dissipated. "If Brazil had lost," he said, "we don't know …"

But the dissatisfaction in Brazil goes deeper than just public services. Some argue excess consumerism is indeed part of the problem. "This easy money given out did not enrich them. They are in this madness of consumption. Brazilians consume too much, like Americans," said Papoula de Almeida.

Brazilian consumers are also poorly served, by companies that sell them badly produced goods and services at inflated prices. People often take to YouTube or Twitter as the only way to get their complaints dealt with.

So much so that one comedy sketch, in which comedy actor Fábio Porchat gradually loses control as he tries, and fails, to cancel a line with a mobile phone company, became a national sensation and has been seen 11m times on YouTube. "Companies still treat their customers really badly. Brazilians are beginning to lose patience with many things here," said Porchat.

This also plays into protests – many of which targeted the mainstream Brazilian media, particularly Globo. Tens of thousands turned to the independent collective Mídia Ninja, which broadcasts live on the internet from demonstrations via mobile phone.

"There is a gap between what the media shows and what Brazilians see. Particularly in relation to social inequality and human abuses. This contributed a lot to the protests in June," said Bruno Torturra, one of Mídia Ninja's founders.

Following his YouTube success, Porchat and a collective of Rio actors founded Porta dos Fundos (Back Door), which reaches millions of viewers with beautifully filmed and cleverly observed comedy sketches on YouTube. It is like watching The Office when all that television has to show is The Generation Game.

Although Porchat also appears on a family Globo comedy, he says Porta dos Fundos has filled a gap that Brazilian television's conservative nature and obsession with figures has missed.

"We are living a very square moment in terrestrial and cable television here in Brazil," he said. "There is a bigger preoccupation with viewing figures and sponsors and artistic quality has practically been left aside."

Many who sympathise with demonstrators have been put off taking part by the violence with which the police have often dealt with protests. On 20 June, Rio police cleared half a million people off the streets in a matter of hours with teargas, rubber bullets and percussion grenades. Many of these were from poorer backgrounds. "I tried to go to one protest, but there were police and bombs and confusion and I was with my son," said Quel Santos, 30, an unemployed single mother who lives in a favela in Santa Teresa, central Rio. "It was horrible. So we didn't go down."

And a key underlying problem, which Brazilians recognise is fundamental, is the country's endemic corruption – something Dilma Rousseff, the president, has been unable to stamp out. "These are not protests against the Dilma government. They are protests against corrupt politicians, a fragile justice system, corrupt mayors," said Hatoum. "They are liars, greedy opportunists who do not think about the country, they don't think about citizens. This is the perception I have of Brazilian politicians."

Come 2014, if the economy fails to splutter back into life, millions of Brazilians could return to the streets. "There will be confusion. There will be protests. It is not going to end," said Quel Santos. "The people are indignant. And the World Cup will be an opportunity for them to show this to the world."