Moody's Investors Service raised Spain's sovereign debt rating and outlook on Friday, citing progress in economic rebalancing, structural reforms and improved market access after around five years of a deep economic downturn.
The ratings agency increased the sovereign one notch to Baa2 with a positive outlook.
The move comes as Spain emerges from one of its deepest recessions in decades, struggles with record high unemployment - with one of four of the workforce out of a job - and fights to narrow one of the euro zone's widest public sector deficits.
Moody's last revised Spain's outlook from negative to stable in December after cutting its rating to one notch above junk in 2012.
The country lost its top credit rating at Standard & Poor's in January 2009, followed by Fitch Ratings and Moody's in 2010.
"We wanted to acknowledge the progress Spain is making in turning the economy around, rebalancing away from real estate residential investment credit boom toward a more export-orientated model," said Kathrin Muehlbronner, a senior credit officer with Moody's.
Spain has been at, or close to, recession since a decade-long property bubble burst in 2008, sending millions to the unemployment lines and gutting once-strong domestic demand, a key pillar for the country's economy.
With household and business spending badly damaged, many companies turned beyond Spanish shores, making exports one of the only growth areas in the last few years.
"Not a recovery that is very, very strong, but we feel more confident that there is a sustainable recovery here," Muehlbronner said.
The agency praised Spain's progress on structural reforms, notably labour market reform that has helped make hiring and firing more flexible and a restructuring of the banking sector, hard hit by the property crash.
However, the ratings agency warned that the outlook and rating would face downward pressure if economic improvement or fiscal consolidation stalled.
Spain has one of the highest budget deficits in the euro zone, but has managed to almost halve the size of the gap in the last few years through stringent austerity measures including tax hikes and spending cuts.
Moody's also said the country's creditworthiness was constrained by a high debt-to-GDP ratio, expected to top 100 percent this year, a relatively weak banking system and high unemployment.
"The outlook, and eventually the rating, could come under pressure if the economic improvement or fiscal consolidation stalled," the agency said in a note.
"While significantly less likely than a year ago, significant further bank recapitalisation needs or renewed and sustained concerns over market access would also be negative for the rating."
Appetite for Spanish debt by investors has been growing since hitting a low in summer 2012, the height of the euro zone debt crisis. Bond yields fell back toward eight-year lows on Friday.
The yield of benchmark 10-year bonds on Thursday dropped to the lowest level at a primary auction since 2006, while yields on a 30-year bond on offer also dropped to a near six-year low.
Spain is currently rated one notch above junk at Standard & Poor's, at BBB-minus, with a stable outlook, while Fitch has Spain at two notches above junk, at BBB, with a stable outlook.
The Spanish government declined to comment on the rating move.