The creator of hit TV series the West Wing penned the letter to his daughter and her mother on the morning after the election, saying: "The Klan won last night”.

He said Trump’s victory was also a win for his supporters – including “white nationalists, sexists, racists and buffoons”.

But writer Mr Sorkin, whose works include courtroom drama A Few Good Men and later films The Social Network, Moneyball and Steve Jobs, said the battle has "just begun".

How did America vote? A breakdown by race and gender

Here is his letter in full:

“Sorkin Girls, well the world changed late last night in a way I couldn’t protect us from. That’s a terrible feeling for a father.

“I won’t sugarcoat it—this is truly horrible. It’s hardly the first time my candidate didn’t win (in fact it’s the sixth time) but it is the first time that a thoroughly incompetent pig with dangerous ideas, a serious psychiatric disorder, no knowledge of the world and no curiosity to learn has.

US President-elect Donald Trump (Getty)

“And it wasn’t just Donald Trump who won last night—it was his supporters too. The Klan won last night. White nationalists. Sexists, racists and buffoons. Angry young white men who think rap music and Cinco de Mayo are a threat to their way of life (or are the reason for their way of life) have been given cause to celebrate.

“Men who have no right to call themselves that and who think that women who aspire to more than looking hot are shrill, ugly, and otherwise worthy of our scorn rather than our admiration struck a blow for misogynistic s******** everywhere.

The former leader of the KKK publicly backed Trump in the White House race. (William Thomas Cain/Getty)

“Hate was given hope. Abject dumbness was glamorized as being “the fresh voice of an outsider” who’s going to “shake things up.” (Did anyone bother to ask how? Is he going to re-arrange the chairs in the Roosevelt Room?)

“For the next four years, the President of the United States, the same office held by Washington and Jefferson, Lincoln and Teddy Roosevelt, F.D.R., J.F.K. and Barack Obama, will be held by a man-boy who’ll spend his hours exacting Twitter vengeance against all who criticize him (and those numbers will be legion). We’ve embarrassed ourselves in front of our children and the world.

“And the world took no time to react. The Dow futures dropped 7,000 points overnight. Economists are predicting a deep and prolonged recession. Our NATO allies are in a state of legitimate fear. And speaking of fear, Muslim-Americans, Mexican-Americans and African-Americans are shaking in their shoes. And we’d be right to note that many of Donald Trump’s fans are not fans of Jews. On the other hand, there is a party going on at ISIS headquarters. What wouldn’t we give to trade this small fraction of a man for Richard Nixon right now?

“First of all, we remember that we’re not alone. A hundred million people in America and a billion more around the world feel exactly the same way we do.

“Second, we get out of bed. The Trumpsters want to see people like us (Jewish, “coastal elites,” educated, socially progressive, Hollywood…) sobbing and wailing and talking about moving to Canada. I won’t give them that and neither will you. Here’s what we’ll do…

“…we’ll f*****g fight. (Roxy, there’s a time for this kind of language and it’s now.) We’re not powerless and we’re not voiceless. We don’t have majorities in the House or Senate but we do have representatives there. It’s also good to remember that most members of Trump’s own party feel exactly the same way about him that we do. We make sure that the people we sent to “Washington—including Kamala Harris—take our strength with them and never take a day off.

Hillary Clinton urges supporters to give Donald Trump a chance to lead

“We get involved. We do what we can to fight injustice anywhere we see it—whether it’s writing a check or rolling up our sleeves. Our family is fairly insulated from the effects of a Trump presidency so we fight for the families that aren’t. We fight for a woman to keep her right to choose. We fight for the First Amendment and we fight mostly for equality—not for a guarantee of equal outcomes but for equal opportunities. We stand up.

“America didn’t stop being America last night and we didn’t stop being Americans and here’s the thing about Americans: Our darkest days have always—always—been followed by our finest hours.

"Roxy, I know my predictions have let you down in the past, but personally, I don’t think this guy can make it a year without committing an impeachable crime. If he does manage to be a douche nozzle without breaking the law for four years, we’ll make it through those four years. And three years from now we’ll fight like hell for our candidate and we’ll win and they’ll lose and this time they’ll lose for good. Honey, it’ll be your first vote.

“The battle isn’t over, it’s just begun. Grandpa fought in World War II and when he came home this country handed him an opportunity to make a great life for his family. I will not hand his granddaughter a country shaped by hateful and stupid men. Your tears last night woke me up, and “I’ll never go to sleep on you again. Love, Dad.”