Spain was forced to seek a bailout this weekend, becoming by far the largest country to need help during Europe’s 2 1 / 2-year-long economic crisis. But it was tiny Greece that pushed Spain over the brink.

Greek voters head to the polls Sunday with a stark choice between leaders who accept the harsh terms of the bailouts that have kept their country afloat and those who reject them, potentially at the cost of Greece’s future in the euro zone. Fears that a Greek rejection would send markets into panic about the currency union’s future pushed Spain to seek the aid ahead of Greece’s election.

But the mere possibility of a victory for anti-bailout forces in Greece helped exacerbate Spain’s problems in the first place, boosting its government’s borrowing costs and causing a slow-motion bank run that weakened its financial system. That spiraling confidence problem — in which the 17 countries that share the euro currency are united enough to spread their problems to one another but not enough to guarantee an end to them — is what Europe’s leaders are racing to fix with a road map to further economic integration that could come at the end of the month.

At the moment, those leaders are working to protect the rest of the euro zone from whatever happens when Greece votes Sunday. Greece’s anti-bailout politicians have wagered that the unpredictable consequences of the currency union’s kicking out a member will force Europe to support them regardless. The urgency with which Spain was pushed to take a bailout — the International Monetary Fund sped up by three days an estimate of how much money the country’s banks might need — is a sign of continued worry among Europe’s leaders that Greece’s anti-bailout agitators are right: Their country is too important to write off.

In the United States, President Obama is worried that bad economic news from Europe could dampen America’s struggling recovery, and with it his reelection chances. He has, in recent days, expressed unusually direct concerns about Europe’s management of the crisis.

A balancing act

For now, Europe is still playing hardball with Greece, and the bailout of up to $125 billion for Spain may help leaders keep up their stiff resolve against Greece. Germany’s central bank said last month that Greece’s exit from the euro zone would be difficult but “manageable” for the rest of Europe.

But the balancing act — talking tough with Greece, while taking big steps elsewhere to guard against turmoil spreading if Greece votes for the bailout critics — is a reminder of the uncertainty Europe still faces. Even with the rescue program for Spain, an anti-bailout victory in Greece could push the borrowing costs of Spain and Italy even higher, analysts say. The countries are large enough that if Italy needs aid and Spain needs more help, Europe’s bailout funds might not be able to come up with the money.

“If Spain got into a catastrophic situation, you could forget French and German banks,” Luxembourg Finance Minister Luc Frieden told the broadcaster RTL on Sunday.

So European leaders have been sending a conciliatory message to Spain and a very different one to Greece.

On Saturday, just hours before Spain asked for the bailout, which will come with fewer strings than were attached to the rescue program for Greece, euro zone chief Jean-Claude Juncker told Deutschlandradio that “the substance remains” that Greece needs to get its budget under control.

Greece, which with 11 million people has less than a quarter of Spain’s population, has received two bailouts in two years, adding up to more than twice the money on the table for its larger European neighbor, in part because Spain’s problems are more confined to the bursting of a property bubble than to overall failures in its government finances.

So, for now, though Spain made the headlines this weekend, the crisis has returned home to Greece, where it started.

European leaders tried to wall off Greece’s problems by pushing the country’s private creditors to write off almost three-quarters of what they were owed. That means that if Greece defaults, the continent’s banks have less to lose than they did just months ago, though governments would lose the emergency aid they extended to the struggling country.

Polls show that a majority of Greeks still want to continue with the euro, and the left-wing Syriza party is gambling that Europe’s fears about contagion are still too high to kick them off.

“We do not need any task force to tell us what to do,” Syriza head Alexis Tsipras said Thursday, the daily Kathimerini newspaper reported. Addressing a rally, he added that he would not fire any civil servants if he were elected. Reducing the public payroll is a key element of Europe’s bailout program for Greece.

Caution from Germany

Worries that Spain would be next if Greece were pushed out of the euro zone contributed to a flight of depositors from Spanish banks in recent months, weakening the institutions to the point where Prime Minister Mariano Rajoy was forced to call in help Saturday after weeks in which he strenuously denied that Spain would need it.

“This year is going to be a bad one: Growth is going to be negative by 1.7 percent, and also unemployment is going to increase,” Rajoy told reporters in Madrid on Sunday, the Reuters news agency reported.

Europe’s leaders are trying to build better-unified structures to backstop the euro zone’s patchwork financial system, but the proposals that will be discussed at a summit June 28 and 29 would take years, not weeks, to be operational. The slow pace is largely attributable to Germany, which as Europe’s largest economy will bear much of the responsibility of paying for whatever new support measures emerge.

German Chancellor Angela Merkel cautioned Friday that Greece had little room to maneuver.

“We want Greece to remain a member of the euro zone,” Merkel told reporters in Berlin. “The prerequisite for this . . . is for Greece’s future government to adhere to the memorandum” that defines the tough terms of its bailout.

But some analysts say that Germany’s caution about faster movement toward European integration can last only as long as its economy remains insulated from the continent’s turmoil.

“The political opposition to further measures at the European Union level will wane as soon as it becomes obvious that Germany is going to be affected by what’s happening outside it,” said Lars Feld, a member of an influential council of economists that advises the German government.