“Hamilton,” the hit Broadway musical about colonial rebels shaping the future of an unformed country, took an even more political turn at the end of its performance on Friday night.

With Vice President-elect Mike Pence attending the show, the cast used the opportunity to make a statement emphasizing the need for the new administration of President-elect Donald J. Trump, a Republican, to work on behalf of all Americans.

It was a deeply felt and altogether rare appeal from the stage of a Broadway show — and it drew a surprisingly sharp rebuke from Mr. Trump on Saturday morning. The president-elect wrote in a post on Twitter that the “Hamilton” cast had “harassed” Mr. Pence by making the statement and had been “very rude.”

“Apologize!” Mr. Trump wrote at the end of one of two posts on the matter.

As the play ended, the actor who played Vice President Aaron Burr, Brandon Victor Dixon, acknowledged that Mr. Pence was in the audience, thanked him for attending and added, “We hope you will hear us out.”