In the latest example of President Trump tangling with celebrity critics on social media, he called the musician John Legend “boring” and the model Chrissy Teigen “filthy mouthed” in tweets late Sunday trumpeting the president’s achievements in criminal justice reform.

Ms. Teigen and Mr. Legend, a married couple who are both frequent critics of the president, fired back. Mr. Legend called on the first lady to intervene, and Ms. Teigen used vulgarities.

By Monday morning, the expletives used by Ms. Teigen — including one that Mr. Trump famously used in a recording that surfaced shortly before his election in 2016 — were part of a trending hashtag on Twitter. A related hashtag, #filthymouthedwife, was also trending.

In his tweets shortly after 11 p.m. on Sunday, Mr. Trump appeared to be responding to Mr. Legend’s appearance at a criminal justice town hall that was hosted by the “NBC Nightly News” anchor Lester Holt at the Sing Sing prison in Ossining, N.Y., and aired on MSNBC at 10 p.m. that night.

The president began by pointing to the criminal justice reform legislation he passed last year.

“Now that it is passed, people that had virtually nothing to do with it are taking the praise,” Mr. Trump wrote. “Guys like boring musician @johnlegend, and his filthy mouthed wife, are talking now about how great it is — but I didn’t see them around when we needed help getting it passed.”

He did not name Ms. Teigen, which she noted in her response. “Tagged everyone but me,” she wrote. “An honor, mister president.” She added that she had not been mentioned in the MSNBC special that Mr. Trump appeared to have watched.

Mr. Legend also jumped into the fray, and he called on the first lady to intervene.

“Imagine being president of a whole country and spending your Sunday night hate-watching MSNBC hoping somebody — ANYBODY — will praise you,” he said. “Melania, please praise this man. He needs you.”

Mr. Trump has often boasted about his own I.Q. and questioned the intelligence of others. He also has a habit of insulting prominent people of color.

Last year’s criminal justice overhaul under the First Step Act was meant to expand job training and other programs to reduce recidivism for federal prisoners; modify sentencing laws, including mandatory minimum sentences for nonviolent drug offenders; and enlarge early release programs.

Mr. Trump considers the bipartisan legislation one of his major accomplishments — one he hopes will broaden his appeal to voters. Some celebrities, including Kim Kardashian West and Kanye West, have been invited to the White House to discuss criminal justice and reducing criminal sentences.

But critics of the administration have raised questions about the pace of enforcement and the funding of the act. They have also noted that it addresses only the federal prison population, a tiny fraction of the people behind bars in the United States. (Mr. Legend has also pointed out that state laws — not federal ones — affect most incarcerated people in the United States.)

Ms. Teigen is a prolific Twitter user who has long criticized Mr. Trump. In 2017, she tweeted that she had been blocked from viewing his account.

“After 9 years of hating Donald J Trump, telling him ‘lol no one likes you’ was the straw,” she wrote.

Both she and Mr. Legend are vocal about their political beliefs and their opposition to the president’s policies. In 2014, Mr. Legend founded FreeAmerica, an organization that highlights injustice in the criminal justice system.