Obama, who landed in Madrid late on Saturday night, visited the King for a reception at the Royal Palace in the center of Madrid at 10:30 a.m. local time.
The pair made a short appearance for the press, with Felipe stressing that the United States was "a friend and a decisive nation on the world," and that Spain and the U.S. shared "principals, values and interests."
In response Obama said that America and Spain "were not just allies, but countries which had the same ideals, among them, freedom and respect for the rule of law," a sentiment he would later repeat following his reunion with Prime Minister Rajoy at his official residence, the Palacio de la Moncloa.
Following discussions lasting around an hour, Obama and Rajoy made declarations which were beamed to the press room in Moncloa via a TV screen.
The pair said they had discussed Brexit and Obama expressed hope that, "negotiations can be managed in a way that does not have adverse effects for Europe and the UK."
"If you believe the exchange of trade, culture and ideas can be a good thing, then it has to be accompanied with policies which ensure workers have fair wages and that the social system is strengthened for the 21st century and addresses environmental issues," Obama said.
Rajoy said Spain would "have a constructive attitude in negotiations with the UK," and that the two leaders had also spoken about "refugees and the problems of Libya and Syria and the need to resolve them as soon as possible.
Both highlighted the close ties between Spain and the United States, which were strengthened by the large "Spanish speaking community" in America.
After concluding his meeting with Rajoy, Obama flew from the military airport of Torrejon, just outside of Madrid, to the U.S. military base at Rota in the southwest of Spain.
There he addressed the 3,000 U.S. troops and civilians living there, telling them the U.S. "couldn't ask for a better ally than Spain," before taking off to return to Washington DC at 8 p.m. local time.
The schedule of Obama's visit to Spain was changed at short notice on Saturday as a result of the shooting of 5 police officers in Dallas. As a result he was in Spain for less than 24 hours and was forced to drop a planned visit to the city of Seville.
Security measures were high during Obama's brief time in the country, but that didn't stop protestors from environmental group Greenpeace hanging a large banner protesting against TTIP negotiations from a building on Madrid's Gan Via.