WASHINGTON—President Trump said he was ending efforts to put a citizenship question on the 2020 U.S. census, marking a major retreat from his declarations in recent days that he wouldn’t give up the fight in the wake of a Supreme Court ruling that effectively blocked the move.

Speaking in the White House Rose Garden on Thursday, Mr. Trump said he would instead sign an executive order requiring all federal agencies to provide the Commerce Department with “all requested records” on the number of citizens and noncitizens in the...