Moody's upgraded the rating to Baa2 from Baa3, and gave the country a "positive outlook", suggesting the potential of a further upgrade.
Spain has made faster-than-expected progress in rebalancing the economy away from real-estate investment, where a 2008 price bubble crash sent the economy reeling, towards exports, the ratings firm said.
Moody's highlighted the authorities' progress in implementing broad structural reforms, especially in the labor market and the public pension system, as well as other measures including the restructuring of the Spanish banking system.
"These efforts support Moody's expectation of stronger, more sustainable economic growth over the medium term and continued improvements in the resilience of government finances."
Spain's economy shrank by 1.2 percent over the whole of 2013, but exited recession in the third quarter with 0.1 percent growth. The eurozone's fourth-biggest economy exited the European Union's financial sector rescue program on January 23rd.
Moody's said business investment was adding momentum, consumer confidence was improving and both the corporate and household sectors continued to reduce their high debt burdens.
"Moreover, competitiveness gains have been substantial and will continue to underpin the export sector as wage growth will likely remain very moderate in the coming years," the company said.
"Overall, the rebalancing of the economy has proceeded faster than Moody's had previously expected."
Prime Minister Mariano Rajoy's conservative government is banking on exports to be an engine of recovery for Spain. It has changed labor rules to give companies more power to cut wages, fire workers or modify their jobs to boost competitiveness.
Earlier Friday, the Spanish government reported the nation's trade deficit fell by almost half in 2013 as exports hit a record, driven by a push by Spanish firms into new markets outside Europe.
Spain's trade deficit tumbled to €15.9 billion ($21.8 billion) as exports rose 5.2 percent to €234 billion.