Ben Carson’s first full week as secretary of Housing and Urban Development got off to a rough start on Monday after he described African slaves as “immigrants” during his first speech to hundreds of assembled department employees. The remark, which came as part of a 40-minute address on the theme of America as “a land of dreams and opportunity,” was met with swift outrage online.

Mr. Carson turned his attention to slavery after describing photographs of poor immigrants displayed at the Ellis Island National Museum of Immigration. These new arrivals worked long hours, six or seven days a week, with little pay, he said. And before them, there were slaves.

“That’s what America is about, a land of dreams and opportunity,’’ he said. “There were other immigrants who came here in the bottom of slave ships, worked even longer, even harder for less. But they too had a dream that one day their sons, daughters, grandsons, granddaughters, great-grandsons, great-granddaughters, might pursue prosperity and happiness in this land.”

The comparison was first reported by USA Today and quickly drew the ire of social media users who attacked the secretary, who is African-American, for what they saw as racially insensitive comments. On Twitter, the comedian and actress Whoopi Goldberg recommended Mr. Carson watch the 1980s mini-series “Roots.”

Ben Carson..please read or watch Roots, most immigrants come here VOLUNTARILY,cant't really say the same about the slaves..they were stolen

The Department of Housing and Urban Development was stunned by the uproar and spent part of the afternoon responding to the news media on Twitter. In a statement, it said critics were watching only a short clip from a 30-minute speech and were viewing the remarks in bad faith.

“This is the most cynical interpretation of the secretary’s remarks to an army of welcoming HUD employees,” the department said in a statement. “No one honestly believes he equates voluntary immigration with involuntary servitude!”

A spokesman for the department said Mr. Carson’s speech appeared to cause little upset among the employees who had gathered to hear him speak. Several hundred people attended the event and many lingered afterward to snap selfies with Mr. Carson, who was sworn in last Thursday.

An error has occurred. Please try again later.

You are already subscribed to this email.

On Monday night, following a radio interview in which he defended his remarks earlier in the day, Mr. Carson also did so on Twitter. “You can be an involuntary immigrant,” he said, adding that “slaves didn’t just give up and die, our ancestors made something of themselves.” He continued, “An immigrant is: ‘a person who comes to live permanently in a foreign country.’”

But later that night, on Facebook, Mr. Carson drew a clear distinction between immigrants and slavery: “The Immigrants made the choice to come to America. They saw this country as a land of opportunity. In contrast, slaves were forced here against their will and lost all their opportunities. We continue to live with that legacy.”

Mr. Carson’s speech was not the first time that a newly minted Trump official has caused offense with their handling of African-American history.

Mr. Trump himself has described “inner city” neighborhoods as a crime-ridden “hell” in need of a tough police response, a vision of urban life that has been received unfavorably by many minority leaders.

Last week, the new education secretary, Betsy DeVos, caused an uproar by describing historically black colleges and universities — founded because black students were not allowed to attend segregated white schools — as “real pioneers” of school choice.

She later backtracked, saying in a statement that the history of black colleges and universities “was born, not out of mere choice, but out of necessity, in the face of racism, and in the aftermath of the Civil War.”

Jack Begg contributed research.

A version of this article appears in print on March 7, 2017, on Page A13 of the New York edition with the headline: Online Uproar After Housing Secretary Refers to Slaves as ‘Immigrants’ in a Speech. Order Reprints|Today's Paper|Subscribe