MADRID — In his first visit to Catalonia since taking control of the restive region in Spain, Prime Minister Mariano Rajoy on Sunday urged Catalans to vote in next month’s elections to defeat the independence movement and return the region to “normality.”

Mr. Rajoy, addressing Catalan supporters of his conservative Popular Party, rejected criticism of the jailing of separatist politicians, a day after hundreds of thousands of pro-independence demonstrators marched in Barcelona, the Catalan capital, to demand their release.

“In Spain, you can defend any idea,” Mr. Rajoy said, but only as long as it is done within the rule of law.