"We expect Spain's GDP will expand faster than the eurozone average over 2018-2021, and that the government's budget deficit will continue to shrink," it said in a statement.
"As a result, we are raising our unsolicited long-term sovereign credit ratings on Spain to 'A-' from 'BBB+' and assigning a positive outlook," it said.
Another ratings agency, Fitch, had upgraded Madrid's sovereign debt rating in January.
"The positive outlook signifies that we could raise our ratings on Spain within the next 24 months if the government achieves greater consolidation of public finances than we currently expect," S&P said.
"Further easing of political tensions in Catalonia would also support an upgrade," it said.
Catalonia, which was previously an autonomous region, remains under direct rule from Madrid, which was imposed after the region declared independence in October.
The move came after Spain's central bank this week increased its growth forecast for 2018 to 2.7 percent from 2.4 percent as the government plans to reduce income tax for some workers and hike wages for civil servants.
It said this reduction in the tax burden would however lead to a slower drop in the public deficit this year, which it predicts will reach 2.5 percent of GDP -- still below the 3.0 percent limit set by the European Union.
The Spanish government had planned for a deficit of 2.3 percent in 2018.
The central bank also predicts economic growth will be slightly higher than expected in 2019.
In a statement, it put stronger growth down to debt reduction in the private sector and a current account surplus.
It is also expecting a general drop in the tax burden on people in Spain.
The government is expected to adopt its budget for 2018 at the end of March, very late due to the secession crisis in Catalonia. This will then be submitted to a vote in parliament.
READ ALSO: Spain's credit rating gets upgrade thanks to rosier economy