MADRID — The days of Spain playing a bit role in Brussels are finally coming to an end.

Madrid has a great opportunity to shape EU politics and policies over the next five years. Italy and Poland — not to mention the U.K., which is tearing itself apart over Brexit — are weak. Benelux, the Netherlands especially, has lost its enthusiasm for an ever-closer union. And the Franco-German alliance is casting around for new partners to champion closer cooperation on defense, migration and the future of the euro.

Fortunately, such a partner is close at hand. Spain’s prime minister, Pedro Sánchez, has become the de facto leader of European social democracy, the second biggest political family in both the European Council and the Parliament. As the EU embarks on another term of policymaking, all signs indicate he has learned from the mistakes of his predecessors and that he’s determined to make his mark on the European project.

For too many years, Spain has punched below its weight in Brussels.

This dynamic started in the 1980s, when then Prime Minister Felipe González got Spain into the European club by agreeing that Madrid would open Spain’s market to the big firms of its northern neighbors in exchange for a scheme that would compensate the losers of this process. It marked the start of the EU’s structural and cohesion funds — a great achievement, but also a curse.

Spain is starting to do something others have long figured out: It is building its own network in the European capital.

Once EU funding was secured for badly needed infrastructure — Spain had hardly any motorways — and the protection of rural areas, Spanish politicians focused their foreign agenda elsewhere.

Spain became a reactive player in EU affairs. Its pro-European stance meant that it would always be in favor of further integration, but its goals were limited to following the course set by Berlin and Paris.

This passive role came with a price. In the middle of the debt crisis and its aftermath, Spain lost influence, while others — Italy and Poland, but also small member countries such as Finland, Ireland and Portugal — started to take up more space. Strikingly, Spain even lost its permanent position on the European Central Bank’s executive board.

Spain learned the hard way that domestic weakness made it weak on a European level. And it found that this is a two-way street. If you are weak in Brussels, national unity will suffer too. The Catalan secessionist movement is a case in point.

More than any other Spanish leader before him, Sánchez appears to grasp the implications of this dynamic and — thanks to his understanding of how the EU works — has a plan to break the vicious cycle.

His interest in the Continent is reflected in his Europe team: His economy minister, Nadia Calviño was a director general in the European Commission; his foreign affairs minister, Josep Borrell, was president of the European Parliament; and Luis Planas, his agriculture minister, was Spain’s permanent representative in Brussels. Other top officials are strong pro-Europeans who understand the workings of the EU machine.

To be sure, the Spanish Socialists aren’t in an easy position domestically: They are set to have a minority government and the vexed issue of Catalonia’s push for independence won’t go away any time soon. Sánchez is also facing strong criticism for reaching agreements with the radical left and independentist parties to pass certain laws and the budget.

What will give the prime minister leverage on the European stage, however, is a strong pro-European consensus among Spaniards. The country’s Euroskeptic party, Vox, suffered a big defeat in last month’s European election with only 6.2 percent support — far below the 34 percent far-right leader Matteo Salvini received in Italy or the 30 percent of Brexit Party chief Nigel Farage.

A tide seems to have turned in Spain. Both government and non-government actors are determined to enhance the country’s influence in the bloc — especially now that the country is likely to become a net contributor to the project.

Indeed, Spain is starting to do something others have long figured out: It is building its own network in the European capital. Spanish officials in the institutions now meet regularly to share and coordinate their positions. They’ve also started systematically conferring with their counterparts in the Spanish government, MEPs and multinational Spanish companies.

Madrid is also finally learning how to play the EU game when it comes to lobbying, despite the fact the word comes with strong negative connotations in Spain. This is especially important now that Madrid seems set to become a net contributor to the EU budget.

Here, of course, cooperation with Germany and France will be crucial, but Spain will also have to find key allies in smaller member countries.

All signs point in the direction that Spain will not only be shaping the bloc’s politics, with appointments in key EU decision-making positions, but charting the course when it comes to policy too.

Sánchez's sherpa, José Manuel Albares, recently disclosed Spain’s strategic agenda for the next Commission, which highlights 10 key priorities: completing the European monetary union, strengthening Europe’s social policies, creating an industrial policy, deepening the single market, developing a green new deal, support for SMEs and rural areas, more investment for high tech, smart management of migration flows, a greater global role for the EU, a bigger EU budget and more fiscal harmonization.

Here, of course, cooperation with Germany and France will be crucial, but Spain will also have to find key allies in smaller member countries. It doesn’t have anything to gain from becoming a third wheel to France and Germany.

Instead, it should date around — using its position as the leader of European social democracy to develop relationships with new partners across the bloc.

Miguel Otero-Iglesias and Ignacio Molina are senior analysts at the Elcano Royal Institute in Madrid.