After Fernando Torres went close with a spectacular volley, Vicente del Bosque's team grabbed the lead in the eighth minute with a low drive from 25 yards by Santi Cazorla.
The Spaniards doubled their advantage in the 19th minute when Juan Mata chipped the ball to Cesc Fabregas, who glanced in a header.
It looked likely to be a one-sided game with Spain strolling around and Haiti, who have struggled in recent years in CONCACAF competition, chasing the ball in the heat and humidity.
Spain introduced Barcelona midfielders Andres Iniesta and Xavi in the second half and almost made it 3-0 when Roberto Soldado struck the post in the 70th minute.
But Haiti stuck at the task and delighted their fans in the 36,535 crowd at Sun Life Stadium with a goal in the 76th minute.
The ball fell to left back Wilde-Donald Guerrier, who showed electric pace and great composure to burst past the Spanish defence, round substitute keeper Pepe Reina and slot home.
It was just reward for Haiti's efforts but Spain kept their cool in the final minutes to ensure they avoided a potentially embarrassing scoreline.
"In the first half, I think we played to our level, we controlled the ball and created chances," said Del Bosque.
"After the break we put less pressure on, played with less intensity and Haiti were able to see more of the ball and play better, but overall it was a good test for us."
The biggest smile after the game was on the face of Haiti goalscorer Guerrier, who revealed that his son Cristiano, named after Real Madrid winger Cristiano Ronaldo, had been born just a day before the game.
"It was a great honour to play against the world champions and I think we showed that Haiti is not only about the earthquake we had, but we showed that we have talent," said the defender.
"I was very pleased to get a goal against the number one team in the world. They are great players but they are human beings, they aren't from another planet."
The Spaniards play another friendly, against Ireland on Tuesday at New York's Yankee Stadium, before heading to the Confederations Cup in Brazil where they will face Uruguay, Nigeria and Tahiti in Group B.
Haiti will also head to Brazil to play Italy in a friendly on Tuesday, which will also serve as a fundraiser for the victims of the 2010 earthquake in the country.