Two months ago, Roseanne Barr was a star again.

Her sitcom “Roseanne” returned in March after a two-decade absence to enormous ratings on ABC. Network executives were celebrating their strategy of appealing to wider swaths of the country after Donald J. Trump’s surprising election win and the president himself called Ms. Barr to congratulate her on the show’s large audience.

But on Tuesday, that all came crashing down. ABC abruptly canceled “Roseanne” hours after Ms. Barr, the show’s star and co-creator, posted a racist tweet about Valerie Jarrett, an African-American woman who was a senior adviser to Barack Obama throughout his presidency and considered one of his most influential aides. Ms. Barr wrote if the “muslim brotherhood & planet of the apes had a baby=vj.”

Ms. Barr later apologized, but it was too late. In announcing the show’s cancellation, ABC’s entertainment president, Channing Dungey, said in a statement that “Roseanne’s Twitter statement is abhorrent, repugnant and inconsistent with our values.”

“Roseanne” had ended its successful comeback season last week and was expected to return in September for a 13-episode run. Robert A. Iger, the chief executive of the Walt Disney Company, ABC’s corporate parent, shared Ms. Dungey’s statement on his own Twitter account, adding: “There was only one thing to do here, and that was the right thing.”

The sudden cancellation of a hit show — it had the highest ratings of a new TV series in years — because of offscreen controversy was almost without precedent.