President Barack Obama spent the past four days in Europe visiting his two oldest and closest foreign political allies, spending considerable political capital on issues close to their hearts.

The time and energy put into the visits to London and Germany - likely the last of his presidency - signaled Obama's affection and trust for two leaders who have stood with him through his toughest economic and foreign policy decisions.

But the trip also highlighted Obama's concerns about the shaky global economy and the ripple effects of the conflict in Syria - priorities he wants to work on before his term ends next Jan. 20.

"My goal between now and the time I leave is to make sure that when I turn over the keys to my office, that the desk is clean, and if the world is not completely tidy, that at least it's significantly better off than the way I found it," Obama told reporters in Hanover, Germany.

In London, Obama dove right into the biggest domestic policy question facing the United Kingdom, as he tried to convince Britons to remain part of the European Union when they vote in a referendum scheduled for June.

His backing for his friend Prime Minister David Cameron, who is leading the "remain" campaign in the referendum, shows any concerns the White House may have had about the appearance of meddling in another country's affairs were far outweighed by worries about what a Brexit would do to the economy.

In Hanover, a small city in northern Germany off the beaten path for U.S. presidents, Obama spent hours at a massive trade fair looking at displays and talking up the economic benefits of a U.S.-EU trade deal at the personal invitation of Chancellor Angela Merkel.

Before his term ends, Obama would like to finish negotiations with the EU on the Transatlantic Trade and Investment Partnership (TTIP), the second of two broad deals he believes will boost the U.S. economy.

The first deal, the Trans-Pacific Partnership (TPP), is further along but needs final approval from Congress, which Obama hopes will come later this year.

Trade has become a touchy political issue at home and abroad.

"Time is not on our side," Obama told business leaders in Hanover. "If we don't complete negotiations this year, then upcoming political transitions in the United States and Europe would mean this agreement won't be finished for quite some time."

The TPP has come under fire from both Democratic and Republican presidential candidates, diminishing the prospects that it will come up for a vote in Congress before the Nov. 8 election.

Militants and migrants

Hanging over Obama's economic talks was the Syria conflict, which has left Europe grappling with a flood of migrants. Obama also has been looking for ways to boost momentum in the fight against Islamic State militants.

While in Hanover, Obama announced he would send 250 more troops to help local groups battling Islamic State, the biggest hike since the war began, aimed at helping local militia gain the upper hand.

He and Merkel also held huddled with Cameron, French President Francois Hollande and Italian Prime Minister Matteo Renzi on urgent issues including migration and renewed fighting between government forces and opposition groups.

Obama has acknowledged the Islamic State fight will last well beyond his time in office.

He kicked off his trip in Riyadh, where he tried to reassure Gulf Arab leaders that Washington's commitment to the Middle East has stayed strong, and pledged to "deter aggression" against allies.

Star power

The trip was not all business. Obama visited members of Britain's royal family, including Queen Elizabeth, and took Cameron golfing at a swanky course.

In Hanover, Obama and Merkel took front-row seats for an interpretative dance performance set to techno music involving robots and break-dancers. Later, they had dinner with a group of high-powered chief executives from Germany and the United States.

Obama remains popular in Europe and the UK, while Merkel and Cameron have been hurt in the polls over the migrant and Brexit issues, respectively.

Obama's visit was big news and lent some of his star power to his friends.

"He is a popular figure in Germany, and so for him to come and be supportive of (Merkel), particularly on the refugee and migration issue ... is helpful to her," said Karen Donfried, president of the German Marshall Fund and a former adviser to Obama.