Samurai Blue fell behind in the 11th minute of the contest, with Alvaro Morata making the breakthrough, and it was a dominant first-half performance from Luis Enrique's side.
However, Japan levelled the scores in the 48th minute through Ritsu Doan before Ao Tanaka won it three minutes later when he converted from close range, with the national side topping the group.
There was controversy about the winning goal, though, as the ball looked to be out before it was delivered into Tanaka by Kaoru Mitoma.
Moriyasu called Spain "one of the best teams in the world" and hailed his players for managing to navigate their way past Enrique's team to top the section.
"Spain are one of the best teams in the world and we knew before the game that this was going to be very difficult, and indeed it was," Moriyasu told reporters.
"But the players persisted and they persevered and they turned the tide of the game. Everybody was excited that we were able to play as one again.
"There were many fans who came all the way from Japan, as well as those that stayed at home. We are gifting this win to the people of Japan, and we are very happy about it.
"During training, we confirmed a few things and the players gave me some ideas. We decided that we were going to defend and try to counter-attack... it was a choice of all of us collectively.
"I couldn't decide on the tactics, and at the end of training, we had a few options. We talked together with the players and chose a certain option from them. Now all the people of Japan can share our happiness.
"Whether the ball was out or not (for the winning goal), there is great technology nowadays for big football, and if it was really out, it would have been a goal kick.
"But the judgement of the referee is that it was in - and we respected that. We were able to accept it either way - and in the end, it was decided it was in."
Japan will take on Croatia in the last-16 stage of the competition on Monday.