You’d think White & Case might be a little leery of opening new offices, considering the dozens of lawyers the firm has shed over the past several years. You’d also think the firm might not want to set up shop in economic trouble spots—and especially not in certain southern European countries still dealing with the fallout from the global financial crisis and a catastrophic real estate collapse. Spain, for instance.

So the new office that White & Case opened in Madrid in March raises the question: What in the world are they doing?

Even Oliver Brettle, a London-based partner who sits on White & Case’s executive committee, acknowledges that the Madrid outpost is something of a gamble. Still, in spite of Spain’s acute problems—which include a recent near-collapse of the banking system and an unemployment rate of 26 percent—he believes it’s a solid bet. “We obviously assessed the opportunities and the risks,” says Brettle, who notes that the firm had been considering opening in Spain for the past decade. “We thought that this was the right time.”

White & Case isn’t the only firm that’s been placing bets on the Spanish market lately. This past May, Clyde & Co, a London-based firm specializing in insurance law, launched in Spain after luring away a nine-lawyer group, including four partners, from the Madrid office of insurance practice rival DAC Beachcroft. Meanwhile, more established players in the market—including Baker & McKenzie, Linklaters, Allen & Overy, and Herbert Smith Freehills—also have been beefing up their Spanish outposts in hopes of a surge of new work.

Certainly, Spain’s economy appears to be stabilizing. Not only have the most apocalyptic predictions about the country’s future not panned out, but for the first time since early 2011 the country’s latest gross domestic product data actually showed positive growth, meaning the economy, at least technically, is out of recession. (Granted, the growth rate was a mere 0.1 percent, but it’s a start.) The country’s staggering unemployment rate also has started inching down. And Spain’s basket-case banks? Thanks to a € 41 billion European Union bailout, along with massive consolidation and massive ongoing deleveraging, they too appear to be on the mend.

What’s more, foreign investment is on the rise. In the past year hedge funds, private equity funds, sovereign wealth funds, and other foreign investors have been trolling the Spanish market “looking to make the most of the situation,” as Sebastian Albella, a corporate partner in Linklaters’ Madrid office puts it. They have begun snapping up distressed real estate properties and other bargain-basement-priced assets. Last summer, Linklaters advised U.S. private equity firm Centerbridge Partners on the acquisition of roughly 1,400 residential properties in Spain from Banco Santander S.A. subsidiary Banesto. Another recent buyer: Microsoft Corporation founder and multi-billionaire Bill Gates, who in late October laid down € 113.5 million ($155 million) for a 5.7 percent stake in debt-laden Spanish construction giant Fomento de Construcciones & Contratas S.A.

Indeed, thanks to Gates and other deep-pocketed foreign investors, Spain’s recently moribund M&A market is showing signs of life. In the past year, the total value of transactions in Spain has nearly doubled from just over $24 billion to roughly $48 billion, according to the M&A tracking firm Mergermarket Ltd. The number of deals also has climbed (albeit less dramatically) over the same period, from 255 to 271.

“I think we’re seeing the light at the end of the tunnel,” says Inaki Gabilondo, Spain managing partner at Freshfields Bruckhaus Derringer. “It’s not a very bright or shiny light, but it’s there.”

For Spanish lawyers, the silver lining of the 2008 crash was a spike in restructuring and employment work, as well as financial crisis-related litigation, which helped local law firms ride out the worst of the downturn. Today, with no end in sight to the myriad claims against Spain’s many failed banks, litigation is likely to continue to be a steady revenue-generator for firms. It’s certainly helping market newcomer Clyde & Co, according to Madrid partner Ricardo Garrido. Among other matters, he says the firm is defending insurers in one of Spain’s biggest suits—stemming from the government’s failed bailout and disastrous 2011 public offering of shares in the bankrupt financial giant Bankia. And at Baker & McKenzie, Spain managing partner José Maria Alonso says the recently expanded 20-lawyer litigation group is representing major banks in a consumer class action tied to the “floor clauses” for mortgages, along with handling a wide range of financial crisis-related contractual disputes.

Thanks to new tougher capital reserve requirements, Maria Alonso and other Madrid-based lawyers point out, Spain’s debt-laden banks are now in deleveraging mode. Consequently, they contend that the real near-term action for lawyers is M&A—especially since over the past year Spain’s banks have transferred more than $65 billion of soured real estate properties and loans to SAREB, the so-called bad bank that was created as a condition of the Eurozone bailout—and in the year ahead SAREB will be auctioning off those assets in earnest.

Since May, Clifford Chance has been a major beneficiary of that work, serving as SAREB’s lead outside adviser and project manager, with responsibility for coordinating due diligence and other tasks related to the transfer, packaging and pricing of the “bad” properties. Jaime Velázquez, Clifford Chance’s managing partner in Spain, says the firm expects to wrap up the job by the end of December. For their efforts, Clifford Chance and local counsel, including Cuatrecasas, Gonçalves Pereira and Ramón y Cajal, will collect about € 10 million in fees, according to Velázquez. All told, he says, roughly five dozen distinct portfolios of real estate (including residential properties, commercial buildings, vacation homes, land and more) will be auctioned off. SAREB made its first big portfolio sale this past August, when U.S. private equity fund H.I.G. Capital agreed to pay € 100 million ($133 million) for a 51 percent stake in a package of 1,000 homes in Madrid, Andalusia, the Canary Islands and other parts of Spain. (U.K. firm Ashurst served as H.I.G.’s legal advisers in the transaction, while Baker & McKenzie represented SAREB.) And with SAREB’s assets valued at what Velázquez claims are bargain prices, he notes that private equity and hedge funds have been circling, and he predicts plenty more sales to come. “All these funds are going to make a lot of money in the next five to 10 years,” says Velázquez.

SAREB’s assets aren’t all that’s available for the picking. Along with distressed real estate properties and loans, Spain’s banks have been unloading a wide range of noncore assets to raise capital to repair their balance sheets. The same goes for many of Spain’s biggest companies, which have been divesting a range of noncore holdings to pare down debt. In one of the biggest such deals so far this year, DLA Piper Madrid’s office advised solar-thermal power plant developer Abengoa S.A. on the sale of its industrial waste business to U.K. private equity fund Triton Partners. Freshfields represented Triton in the deal, which was valued at roughly $1.4 billion.

Spain’s cash-strapped government is selling off its assets too. It recently firmed up plans for a partial privatization of state-owned airport operator AENA, and has proposed selling stakes in national insurer CESCE and Spain’s railway. The municipal government of Madrid, meanwhile, has floated its own plan for at least a partial privatization of the city’s water system. “There’s been a lot of discussion of this,” says Juan Manuel de Remedios, managing partner of White & Case’s Madrid office, who notes that the firm is currently working on an IPO for a state-owned entity, although he declined to give specifics.

Even without a wave of privatizations, he and other Madrid-based lawyers don’t foresee any immediate shortage of transactional work. “I think there’s at least a two- to five-year pipeline of private equity deals,” says Juan Jiménez-Laiglesia, Spain managing partner for DLA Piper, which has been advising investment funds Kohlberg Kravis Roberts, CVC Capital Partners and Oaktree Capital Management on potential deals.

In addition to buying up assets, in recent months KKR and other funds also have moved to fill a capital vacuum in the market caused by a pullback in bank lending. One example: KKR agreed in April to provide a € 320 million loan to Spanish construction materials company Uralita S.A. after it was unable to secure bank financing. Since then, Freshfields, White & Case and other firms says they’ve also been advising investment fund clients on similar alternative capital financing arrangements, and they expect to see more such deals in the year ahead.

Given their long-standing ties to many of those funds, it’s no surprise that international firms have been handling an increasing portion of recent M&A work, compared to their Spanish counterparts. “It gives us a big advantage,” says DLA Piper’s Jimenez. And at least as long as foreign investors are driving the deal market, he and other lawyers contend that that’s not likely to change. “Just look at the league tables,” says Clifford Chance’s Velázquez, who points out that in recent rankings compiled by Mergermarket and others, international firms have becoming increasingly dominant players in Spain’s largest transactions.

Top domestic firms insist that they’re still getting a healthy share of new M&A matters. “We think we’re well positioned,” says Mónica Martin de Vidales, cohead of Garrigues’ corporate group. She notes that the firm recently represented Apollo Management Group in its € 60 million ($79 million) acquisition of Evo Bank, a unit of nationalized Spanish lender NCG Banco S.A. Evo Banco was represented by Uría Menéndez. In addition, Garrigues is advising Oaktree, Centerbridge, Silverpoint Capital and other funds on other prospective deals, according to Vidales, who contends that there should be enough work to go around for both domestic and international firms.

De Remedios of White & Case says he’s confident that keeping lawyers busy in the firm’s new Madrid office won’t be a problem: It’s quite likely, he says, that the firm will be hiring more lawyers in the next year to add to the 10 M&A and corporate finance specialists who came from Latham last March. He cites the record turnout at a recent client seminar on restructuring and distressed opportunities in Spain—160 attendees, including investment bankers, private equity and hedge funds, and other professional investors. “People had never seen such a huge crowd,” says de Remedios.

Allen & Overy and Herbert Smith also have been staffing up their local corporate groups with a handful of new hires in the past year, and Linklaters has added 10 new lawyers to keep up with what managing partner Inigo Berricano says has been a flood of new M&A matters. “It’s been a very busy year for us,” says Berricano, “and we think next year will be even better.” Along with its work for Centerbridge, the firm, which now has 110 lawyers in Madrid, recently advised Spanish energy giant Repsol YPF on the $6.5 billion sale of its liquefied natural gas assets to Royal Dutch Shell plc.

Baker & McKenzie has a more limited track record in M&A in Spain. But the firm also has been building its firepower, and with the addition this past summer of 21 corporate and finance lawyers from Spanish firm Ramón y Cajal, Spain managing partner Maria Alonso contends that Baker is in a strong position to compete for deals, especially in the banking sector. “It’s a major achievement for us,” says Maria Alonso of the new hires. Among them, he notes, are Alberto Ureba, former cochair of Ramón y Cajal’s corporate group, and Jose Bauzá, who cochaired Ramón y Cajal’s finance group and brings a client list that includes Citibank Inc., Royal Bank of Scotland plc and Lloyds Banking Group. “We’re confident it’s going to give us a much greater presence not only with financial institutions, but with blue-chip Spanish companies,” Maria Alonso says.

It’s not 2006 or 2007, lawyers caution. “Those were landmark years,” says Clifford Chance’s Velázquez, who doubts that pre-Lehman deal volumes will ever return. Even with the recent spike in volume, Maria Alonso and other local lawyers acknowledge that the M&A market is actually still relatively anemic compared to where it was six years ago. And they’re not expecting a return to prefinancial crisis deal levels or billings any time soon. But the M&A practice is getting busier, one deal at a time.

“It’s easy to destroy a market,” says Alvaro Sainz, managing partner of Herbert Smith’s Madrid office. “Building it up again not that simple.”