Obama is squeezing in a visit to a key NATO and EU partner before dashing home to deal with the aftermath of a wrenching shooting in Dallas.
Greeting King Felipe at the Royal Palace in Madrid, Obama acknowledged that “we've had a difficult week in the United States.”
He has cut a two-day visit to the Iberian peninsula down to one and cancelled a trip to Seville with the king altogether, after a black army veteran killed five white police officers in Dallas.
Obama, who prides himself on his measured approach, is usually loath to alter carefully laid travel plans.
But the shooting — just blocks from the site where John F. Kennedy was assassinated — has pushed a country crackling with political tension to the edge.
Speaking in Warsaw just before Air Force One departed for Spain, Obama insisted the country's divisions were overplayed.
This was not, he insisted, the crisis-ridden era of the 1960s, when US cities burned, the Vietnam War raged and the Kennedy brothers and Martin Luther King were slain.
But his decision to shorten the trip is a tacit acknowledgement that the United States faces a combustible mix of deteriorating race relations, hyper-charged election politics and seemingly never-ending gun violence.
In recent months, videos of deadly mass shootings, or of white police officers killing black civilians, have become routine.
Yet the refusal of America's first black president to scratch the trip to Spain entirely also reflects a determination to fulfil geopolitical goals.
“I want to thank you dearly for visiting us, and very specially for maintaining this visit given the present particular circumstances,” said King Felipe, acknowledging the importance of the visit.
Obama will later visit a US and Spanish Naval Station at Rota, in southern Spain, addressing US personnel who have been stationed at the mouth of the Mediterranean since a deal with Spain's former dictator Francisco Franco.
Since the time of the Greeks, Romans, Moors, Phoenicians and Visigoths, the Bay of Cadiz has been seen as a prime piece of geopolitical real estate.
During the Cold War nuclear weapons were positioned there. Today, Rota has taken on renewed importance with the deployment of four US Aegis destroyers.
They form an integral part of a guided European missile defense system much despised by Russia.
The transfer of the system to NATO control was a key part of an alliance summit in Warsaw which stressed deterring Moscow from destabilizing eastern Europe.
Obama's visit comes as Spain remains mired in a months-old political crisis, with two general elections resulting in no clear victor.
The two centre-left and centre-right parties that have dominated Spanish politics since the return of democracy in the late 1970s have, in the face of insurgent leftists, so far been unable to form a government.
Obama will meet acting premier Mariano Rajoy as well as opposition leaders.
But Obama has a positive note for Spaniards who have suffered years of grinding economic hardship.
“Spain,” he told daily newspaper El Pais, “has travelled a particularly difficult path in recent years.”
He described the brutal blows of a twin financial and economic crisis and austerity policies, which he said, had fueled political discontent.
But, he said “Spain has turned a corner.”
“The economy is growing again, with growth rates that are among the strongest in Europe. There's new hope for the future.”
Dozens of people however braved the heat Sunday at noon to protest outside the US embassy, some carrying signs against the TTIP free trade deal being negotiated between the US and EU, and banners that read “Obama go home” or “War”.
Greenpeace activists meanwhile unfurled a large yellow and black banner on the front of the iconic Metropolis building in central Madrid calling on Obama to stop the deal that read “Yes we can stop TTIP!”.