WASHINGTON — President Trump said Friday that he intended to nominate Robert Wilkie, the acting secretary of veterans affairs, to take over the sprawling agency — a move the president said would surprise even Mr. Wilkie because he had not told him.

The president slipped the announcement into remarks he made ahead of a meeting on prison reform. He praised several members of his cabinet who had worked on the issue, including Mr. Wilkie, “who, by the way,” he said, “has done an incredible job at the V.A. and I’ll be informing him in a little while — he doesn’t know this yet — that we’re going to be putting his name up.”

Mr. Wilkie, who was sitting in the front row at the event, stood up and shook Mr. Trump’s hand after hearing the news. “I’m sorry that I ruined the surprise,” Mr. Trump said.

The Department of Veterans Affairs has been without permanent leadership since the previous secretary, David J. Shulkin, was fired by tweet in March and Mr. Trump’s chosen successor, Dr. Ronny L. Jackson, withdrew from consideration in April after disparaging reports about him circulated before his scheduled confirmation hearing.