Santi Cazorla and Cesc Fabregas both struck in the opening half as Spain applied continual pressure on the home team's defence and the visitors could have been up by at least five goals instead of just two at half-time.
Cazorla opened the scoring in the 42nd minute, blasting home from long range, and Fabregas followed suit in the 45th minute after a pinpoint cross from the right by Jesus Navas.
However, Puerto Rico goalkeeper Bill Gaudette kept his team in the game with a string of fine saves and they eventually scored their only goal, against the run of play, in the 65th minute.
Marc Cintron latched on to a long goal kick by Gaudette and, on the break, buried his shot into the net.
Spain, despite playing a team 137 places below them in the FIFA rankings and whose only four previous matches this year have all been against Nicaragua, failed to come really close to adding to the score.
A notable absentee for Spain was Barcelona playmaker Xavi, who suffered from a niggling calf injury last season and was not selected by coach Vicente del Bosque to allow him more time to prepare for the La Liga season.
Juanfran also limped off with an injury.
Spain begin their qualification campaign for the 2014 World Cup in Brazil away to Georgia on September 11 and are in a Group I which also features France, Belarus and Finland.
- Cesc Fabregas
- Bill Gaudette
- Santi Cazorla
- Jesus Navas