LISBON — After the best part of a decade of recession and stagnation, Portugal finally looked to be getting back on its feet. Then it all went wrong.

In June, just one day after the country had been freed from eight years of EU-imposed austerity measures, forest fires swept through the country, killing 64 people.

“The Portuguese people have been shaken by the greatest catastrophe of recent decades,” Prime Minister António Costa told parliament in his State of the Nation speech. “In less than 24 hours we passed from relief to turmoil, from satisfaction to consternation.”

The fires weren't the only crisis that Costa's government had to deal with over the summer as the mood turned somber in a country that had been on a roll after being crowned European football champions for the first time last summer, had crooned its way to victory in the Eurovision Song Contest, and got its man placed at the head of the United Nations.

Two weeks after the fires, the nation’s self-confidence suffered another blow when thieves broke into a military base northeast of Lisbon.

Their haul reportedly included 44 rocket-propelled anti-tank weapons, 150 hand grenades, 264 blocks of plastic explosives, dozens of detonators and hundreds of rounds of ammunition.

“When the going gets tough, this government disappears" — Opposition leader Pedro Passos Coelho

As rumors circulated that the weapons were destined for international terrorists or organized crime gangs, the heist was viewed as a national humiliation that undermined the trust of NATO allies.

“This calls into question the prestige of Portugal, the prestige of the armed forces, the authority of the state and the security of the Portuguese people,” Marcelo Rebel de Sousa, Portugal’s figurehead president, said after the theft at the base at Tancos.

“I’m demanding a full and complete investigation,” he said. “This has to be done no matter who it hurts, and nobody is immune.”

Costa faced demands for cabinet resignations as his Socialist (PS) government and the center-right opposition traded accusations over who was to blame for defense cuts that left the army with unguarded perimeter fences and broken surveillance systems; greed-driven forestry regimes that made the countryside flammable; chaotic civil defense planning; and investments in dysfunctional communication systems that hindered warnings as walls of flame roared toward defenseless villages and crowded highways.

The prime minister himself was lambasted for vacationing in Spain’s Balearic Islands as security concerns and political tensions rose amid the fallout from the arms heist.

“When the going gets tough, this government disappears,” opposition leader Pedro Passos Coelho told supporters of his center-right Social Democratic Party (PSD). “There’s a lack of leadership and a lack of trust.”

Costa resisted calls to fire his interior and defense ministers, but then faced a further blow when three junior ministers resigned as the state prosecutors’ office was poised to formally name them in an investigation into all-expenses-paid trips to last year’s European football championship in France, allegedly offered by Galp Energeia, a power company.

Popularity persists

Ministers acknowledge the government is facing its most difficult time since coming to power in November 2015.

Still, the Socialists have hit back, claiming that problems behind the fires and the robbery lie with the austerity-driven policies of the previous government led by Passos Coelho. The center-right has also been embarrassed by reports that three of its elected officials accepted a junket paid for by Chinese tech company Huawei.

“It going to be more complicated for Costa this time. The PCP and the Bloc won’t want to lose face, but somebody is going to have to back down" — Political expert André Azevedo Alves

So far, the gloom appears to have done little to hurt the government’s popularity.

Costa remains by far the most popular party leader. He enjoys a 48.9 percent approval rating, according to a poll published Saturday in the weekly Expresso newspaper. With a drop of just 0.6 points over the past two months, he’s way ahead of Passos Coelho on 39.2 percent.

The PS has even increased its lead. Saturday’s poll had the party at 40.8 percent, up 0.4 percent on July. The PSD dropped back to 28.1 percent.

Nor is there any sign that voters disaffected by the summer crises are turning to the two far-left parties that shore up Costa’s minority government.

The Portuguese Communist Party (PCP) is on 7.6 percent and the Left Bloc (BE) on 8.4 percent. Both have been steadily losing support since the October 2015 general election that brought Costa to power.

However, analysts say the summer events could still take their toll.

“So far we haven’t seen any really substantial impact on the polls, but this could mark a turning point over the longer term,” said André Azevedo Alves, a political expert at Lisbon’s Catholic University of Portugal and St. Mary's University, London.

“The tragic scale of the fires and the manner of the robbery at Tancos reflects on the institutions of state and could have a corrosive effect,” he said. “Up until now everything appeared to be going well under this government, we’d been exceeding expectations, now things are going worse than expected.”

Leftists flex their muscles

Costa now faces two crucial mid-term tests: Nationwide municipal elections scheduled for October 1 and the opening on August 21 of negotiations with his far-left partners on next year’s state budget.

The leftists are demanding concessions. After two years of waving through budget bills that have won EU plaudits and brought the deficit down to its lowest level since democracy was restored in 1974, they’re demanding a faster roll back of austerity.

Left Bloc leader Catarina Martins has been addressing party rallies around the country, cranking up pressure over the budget. Her demands range from tax breaks for the low earners to lowering the retirement age and more money for civil servants, pensions and public services.

“We have a country where a mother who works full time and earns the minimum wage lives in poverty because the wage is so low that she cannot support herself and her child,” Martins told a rally Thursday in Monte Gordo, a popular vacation resort in the southern Algarve region. “Nobody should be left behind.”

The very public demands of both far-left parties will make it harder to strike a deal. “It's going to be more complicated for Costa this time. The PCP and the Bloc won’t want to lose face, but somebody is going to have to back down,” said Azevedo Alves. “There are ways out of this, but it will be more of a challenge than in previous years.”

In the rosier economic climate, unions are also demanding more.

Workers at the Autoeuropa car plant — the country’s third biggest exporter — are threatening a strike to interrupt production of Volkswagen’s new T-ROC model. They voted to reject a deal on wages and working time which, the company said, included a 16 percent pay rise for some workers.

Despite his difficult summer, Costa may have less to fear from the local elections than his opponents.

Venezuela is another source of tension between the government and its hard-left backers.

The Portuguese Communists on Thursday issued a statement denouncing protests against Venezuela’s President Nicolas Maduro as “destabilizing, terrorist and putschist.”

The PCP criticized Costa’s government for signing up to the European Union position not recognizing the violence-marred elections that Maduro organized to boost his powers.

Despite the strains, however, neither the PCP nor the Left Bloc have much interest in breaking up the governing partnership, which is popularly nicknamed the geringonça, or contraption.

If they rock the boat too much, they risk being shunted away from power in new elections, given that polls show the PS within reach of an absolute majority, and voters would likely penalize any party that provokes a crisis by pulling out of the governing deal.

That strengthens Costa’s hand in the budget talks.

The local elections will choose mayors and councillors for the country’s 308 municipalities and over 3,000 smaller parish councils. Races are often dominated by local issues and personalities, but the vote will be a barometer of national support for the parties and their leaders.

Costa is hoping the Socialists will increase their current leadership of 150 municipalities, and most of all they want to hang on to Lisbon, where he served as a popular mayor before stepping down in 2015 to run for the premiership.

Fernando Medina, Costa’s successor as mayor, has been riding on a tourism boom, investing in a spate of urban embellishment projects to give the capital a facelift. The party’s national ratings have also been boosted by strong economic data.

Latest Eurostat numbers released last week showed Portugal’s unemployment rate has fallen below the eurozone average for the first time since the crisis; growth, which is predicted at over 2.5 percent this year, will be the “best this century,” according to Costa; and 2017 is on course to be the fifth consecutive record-breaking year for tourist numbers.

The PSD’s challenge hasn’t started well. It’s challenger in the Lisbon mayoral race, Teresa Leal Coelho, made a gaffe-plagued opening to her campaign — confusing Passos Coelho with a previous party leader; making promises to abolish taxes that are beyond the mayor’s remit; and releasing campaign posters apparently missing their slogans.

The party has also suffered a high-profile spat over Passos Coelho’s refusal to disown a candidate running in the commuter town of Loures who spouted pejorative remarks about the local Roma community.

Rivals within the PSD have been sharpening their knives for Passos Coelho ever since he lost the premiership in 2015. A poor showing in October could see the former prime minister ousted.

Despite his difficult summer, Costa may have less to fear from the local elections than his opponents.