The president's remarks mark a departure from the official position of the United States, which, as recently as Monday, was that a planned nonbinding Catalonia referendum Sunday to separate from Spain was an internal matter.
State Department spokeswoman Heather Nauert had said earlier this month that the United States took no position on the referendum.
“We will let the government and the people there work it out, and we will work with whatever government or entity that comes out of it,” Nauert said.
Rajoy's government claims the referendum would violate the country's constitution. He has increased security around the vote, leading to complaints of heavy-handed police tactics and the threat of a return to authoritarianism.
“I think the people of Catalonia have been talking about this for a long time.” Trump said. “I'm just for a united Spain,” he said, adding that if accurate polling were done in the region “you’d find out people of Catalonia love their country, they love Spain.”
The Trump administration strongly opposed another nonbinding independence referendum held Sunday in the Kurdish region of northern Iraq.
Catalonia is one of Spain's 17 autonomous regions. The region of more than 7 million people in the northeast is an economic engine for Spain, and the regional capital Barcelona is a tourist hub. The separatist movement is built on a distinct language, history and culture.
Spanish police have confiscated millions of ballots for the referendum in recent days, the Associated Press reported. They are being distributed to polling places in advance. Madrid is trying to prevent that distribution, and has apparently also destroyed some ballots.