Lea Salonga and George Takei in “Allegiance.” (Matthew Murphy)

As an antidote to the hateful rhetoric spewing from the presidential campaign, you should take in a Broadway musical.

Not to escape the viciousness — to better understand its consequences.

And that is exactly what happened Thursday evening as I sat through “Allegiance” — the new musical starring George Takei of “Star Trek” fame — about the calamitous results for a Japanese American family of being unjustly branded a wartime threat to this nation on the basis of their ethnic background alone. Ruinously forced off their California farm in 1941 and into a camp behind barbed wire in Wyoming, the family endures a deprivation and humiliation that puts you poignantly in contact with a time when American values proved no match for nativist fears.

It isn’t unprecedented for show tunes to broaden one’s perspective of politics or history: “Hamilton,” after all, thrillingly schools audiences in the story of an enterprising immigrant who helped win American independence and organized our financial system.

But when “Allegiance” began performances at the Longacre Theatre on Broadway in early October, it could not have anticipated how profoundly timely its themes would be. Just two months later, the front-runner in polls for the Republican presidential nomination would be issuing pronouncements about barring people from one religious denomination from entering the country. His reasoning was that in the wake of terrorist attacks by extremist killers who were of that faith, millions of others of that background posed too great a threat to the security of the country.

Sound familiar? It certainly did to Takei, forever Mr. Sulu to generations of Trekkies, but more to the point, a prisoner himself as a child for 4 1 /2 years in the Japanese American internment camps during World War II.

The remarks by Donald Trump about halting Muslims’ entrance into the United States galled Takei, as did his recent comment to Time magazine that he “would have had to be there” to know whether he might have supported the Japanese American wartime imprisonment. So the actor took to YouTube this week, to invite Trump to the musical.

Noting that they knew each other — Trump “fired” Takei on a past season of “Celebrity Apprentice” — Takei seized on Trump’s assertion that war forces “tough” choices. Addressing the candidate directly, Takei said: “So if you want to see how ‘tough’ it was from the comfort of your seat, you can be there with us, in the camps, and get a glimpse of what it was like for families who were unjustly imprisoned, thanks to a politics of fear. Much like the one you are campaigning on.”

Throwing down the gauntlet to the heat-seeking Trump was probably a good marketing move. The generally well-received “Allegiance,” by a novice Broadway creative team — score by Jay Kuo and book by Kuo, Marc Acito and Lorenzo Thione — is facing challenges at the box office: The first week of December, it filled only about 60 percent of its seats. But publicizing his invitation served a higher purpose, too, in trying to fortify an understanding of the tragedies that can ensue when the government reacts by blanket condemnation and stereotype.

The historically based “Allegiance” is not the story of Takei’s experience per se, but it comes close. It follows the fictional Kimura family, whose lives are upended after the Japanese attack on Pearl Harbor.

Ordered by the government into detention along with 120,000 other Japanese Americans, the Kimuras struggle to understand a rationale for the belief that they constitute a fifth column.

Telly Leung, center, and the cast perform a song in “Allegiance.” (Matthew Murphy)

Michael K. Lee, George Takei and Lea Salonga in “Allegiance.” (Matthew Murphy)

The political pressures that will rend the Japanese American community afflict the Kimuras. The father, Tatsuo (Christopheren Nomura), wants the family “to keep our heads down,” a point of view expressed in the song “Do Not Fight the Storm.” But his assimilated son Sammy — portrayed by Telly Leung as a recent college grad and by Takei as an old man — wants publicly to prove his loyalty: He petitions the Japanese American Citizens League to lobby to allow him to serve in the armed forces.

“Allegiance” does an excellent job explaining the lingering damage the internment inflicts. The musical is framed by the decades-long estrangement between Sammy and his older sister Kei (Lea Salonga, the original Kim of “Miss Saigon”) after she marries an internee (Michael K. Lee).

Receiving a draft notice after the first waves of Japanese American soldiers proved their mettle, Lee’s Frankie refuses to serve, arguing that a government that would imprison his parents has no right to ask him to take up arms in its defense.

The rage at Frankie that Sammy expresses after returning wounded from the front lines reflects a bitterness that festered long after the war, Takei said in an interview Friday.

“The fracture you saw in the Kimura family is symbolic of the fracture in the Japanese community that still exists today,” he explained. The rifts between those who resisted and those who followed a more cooperative path even came to the fore during the backers’ auditions of “Allegiance” for potential Japanese American investors, he added.

“After some of those readings, that fracture re-emerged. Families were pointing fingers at each other, saying things like, ‘Your father said this and this about my parents, and you vilified them.’ The intensity of the anger remains,” Takei said.

The larger point, of course, is that this legacy was tragically unnecessary. The livelihoods and relationships of thousands of interned people were shattered, to no purpose at all. Takei would dearly love it if the people stirring up a new round of paranoia would come to “Allegiance” and face the illuminating music.