It was the world and European champions’ final match before the tournament starts in Poland and Ukraine on Friday.
The home side were frustrated in a goalless first half by a well-organised Chinese team, with the better of the chances coming for the visitors.
The introduction of Barcelona playmaker Andres Iniesta at half-time made a wealth of difference, and after hitting the bar himself twice, he set up David Silva for the winner six minutes from time.
Spain begin their Euro 2012 campaign against Italy in Gdansk next Sunday, where they are also drawn against the Republic of Ireland and Croatia in Group C.
Vicente del Bosque opted to start with Alvaro Negredo ahead of Fernando Llorente and Fernando Torres, but that failed to bear fruit in a lacklustre first half from the hosts.
Although dominating possession, as is customary, Spain struggled to break down China in the opening period.
The visitors had the more clear-cut opportunities, as Junmin Hao regularly threatened down the flanks and captain Zheng Zhi twice went close.
His first opportunity came just eight minutes in, when the skipper rounded Iker Casillas but could not get his shot on target from a tight angle.
China again almost took the lead after the half hour mark, when Zheng’s shot from a low cross was saved by the legs of Casillas.
Negredo perhaps should have put Spain in front three minutes later when he was played through by Silva, but he could only drag his shot wide of the goal.
Del Bosque freshened things up for the second half, making four substitutions which included the introduction of Iniesta.
He began to pull the strings as Spain started the second period with far more attacking intent and they could have scored far more than they did.
Iniesta forced China goalkeeper Cheng Zeng into a double save in the 54th minute, the second of which was tipped over the bar by the shot-stopper.
The home side then hit the bar twice in two minutes, as Raul Albiol’s header thundered off the frame, before Iniesta curled his shot against the crossbar.
The visitors were struggling to get out of their own half but a rare foray forward 10 minutes from time drew a foul from Torres on the edge of the Spain box. Sun Xiang stung the hands of substitute goalkeeper Victor Valdes from the resulting free-kick.
Valdes got play started again quickly and released Torres down the left, who played in Iniesta to twist and turn in the box and force another fine save from Zeng.
Six minutes from time, Spain got the goal they deserved.
Iniesta was once again involved, as he drilled his run down the left, cut inside the defence and delivered a pass across goal for Silva to tuck the ball into the empty net.
Jesus Navas and Juan Mata both had opportunities to increase the score, but failed to do so in the dying minutes.
The result means the defending champions go into the Euro 2012 on the back of three wins from their three warm-up matches.