Supporters of the conservative Popular Party wave party and Spanish flags next to their party headquarters in Madrid. (Emilio Morenatti/Associated Press)

Manuel Muñiz is the director of the Program on Transatlantic Relations at Harvard University’s Weatherhead Center for International Affairs.

Spain recently ended its longest period without a government since the reestablishment of democratic rule in the late 1970s. It took all of 315 days and two general elections for Mariano Rajoy to succeed in staying at the helm of the Spanish executive for a second term.

Given the seismic developments in Europe, from the self-inflected wound of Brexit, to the political weakness of France’s current president, François Hollande, to the resignation of Matteo Renzi as prime minister of Italy in early December, it now seems that Spain has become an island of stability in a sea of turmoil.

There is talk in Madrid of a window of opportunity for Spain to play a major role in Europe. Some even speak of the possible emergence of a conservative axis connecting Angela Merkel, who is expected to hold on to the chancellorship of Germany after this fall’s federal elections, François Fillon, if he is elected leader of France in the upcoming presidential elections, and Rajoy. The appointment of Alfonso Dastis, an experienced diplomat with abundant knowledge of European Union matters, as Spain’s new foreign minister signals that indeed the country is placing European policy at the core of its international agenda.

This is a wise decision, given the many internal challenges faced by Europe, as well as external tests — including the looming threat posed by Russia in the east and the collapse of Europe’s southern neighborhood which is facing an unprecedented immigration wave that is eroding the popularity of moderate governments across the E.U. Given that the United States, Europe’s most important ally, has elected a Euroskeptic as its next president, political leadership from other E.U. member states is critical.

The opportunity for Spain might therefore be a very real one. The country can become a sensible voice in discussions about furthering much-needed European integration in fields such as security and defense, or immigration policy, and could contribute to keeping Brexit negotiations balanced and steady. It could also play a major role in the rollout of the banking union, arguably the most significant piece of new E.U. architecture to emerge out of the recent euro-zone crisis.

There is an inherent fragility in Spain’s newfound strength, however. There were moments in the past 12 months when many predicted Spain would go down the same uncertain route as Portugal and elect a hard-left government made up of a myriad small nationalist and fringe parties. The current government is only in power because of a brittle set of arrangements arrived at with the Socialist Workers’ Party, itself immersed in an internal crisis that saw its leader, Pedro Sánchez, resign last October, and with Ciudadanos, a small liberal democrat party that only just recently entered the parliament. It is unclear how long this equilibrium will last, particularly after the Socialists elect their new leader in May and begin to assess the impact of being seen as the party responsible for keeping Rajoy as the country’s prime minister. The most pressing test for the new government will, nevertheless, be the approval of this year’s budget, which is expected to be brought to a vote before the parliament by the end of January or early February. The stakes are so high that Rajoy has pledged to resign if he fails to get it approved.

Podemos, a new extreme left party that entered the political scene after winning 8 percent of the Spanish votes in the 2014 elections to the European Parliament, is, according to recent polls, the country’s second-most popular political movement — surpassed only by Rajoy’s Popular Party. Immersed in a primary process, Podemos has been embroiled for the past two months in internal battles pitting its two leading figures, Pablo Iglesias and Iñigo Errejón, against each other. The former defends a more combative Podemos and the latter suggests a normalization of the party and a move toward the center of the spectrum. The result of that clash might well determine the future not only of Podemos but of the entire center left in Spain.

A final issue that is bound to test the mettle of Spain’s current government will be the negotiations regarding the Catalonia region and the desire of the government there to call for an independence referendum. The process has been slowly picking up pace and is bound to reach its climax in 2017, the year chosen by the Catalan government for this plebiscite. This vote faces the staunch opposition of not only the central government but also most of the E.U.’s member states who have no desire to see one of their peers break apart. It is unclear if Catalan nationalists will win the day, but what is certain is that the questioning of Spain’s current territorial composition will surely divert the Spanish government from international matters. If the Catalonia issue is mishandled and the breakup of the country occurs, we would surely see the collapse of the government and fresh elections being called.

Spain has a unique opportunity to contribute in the next months to the resolution of the many challenges Europe faces. This will almost certainly have to be done without the support of the Trump administration and with careful management of some very significant domestic constraints. The Spanish case remains, however, a slim source of hope in a 2017 that has begun with an acute hangover from the political earthquakes of 2016.