Utter chaos enveloped the board of Viacom on Thursday.

National Amusements Inc., the media giant’s controlling shareholder, moved to oust five of the company’s board members, including Chief Executive Philippe Dauman — but the members refused to yield.

The move by NAI “is a brazen and demonstrably invalid attempt” to pirate the Viacom board, Viacom’s lead independent director, Fred Salerno, said in an afternoon statement.

Salerno, not for the first time, claimed Shari Redstone, in a rogue attempt to gain control of Viacom, was behind the move, “in disregard of [her father] Sumner Redstone’s wishes.”

Salerno said the 11-person board did not recognize the ouster and promised it would quickly file suit in a Delaware court to protest her scheme.

But Sumner Redstone appears to have beaten Salerno’s soldiers to the punch — having filed his own Delaware action to gain approval of NAI’s move.

The only thing missing from Thursday’s dustup — the latest in a series of C-suite maneuvers — was the popcorn and 3-D glasses.

NAI has already moved to oust Dauman, a longtime confidant of Sumner Redstone’s, from its board and as a trustee of the Redstone family trust.

At the center of the in-fighting is control of Sumner Redstone’s $40 billion media empire when the ailing 93-year-old mogul dies or is incapacitated.

Dauman claims Shari, once estranged from her dad, has returned to his good graces with a plan to gain control of Viacom, the parent company of MTV, Comedy Central and Paramount Pictures.

The move on Thursday — which included NAI naming five new pro-Redstone directors to the Viacom board — lays the groundwork for the new board to fire Dauman.

Sumner Redstone, once a staunch supporter of his 62-year-old CEO, has steadily lost confidence in the executive as Viacom’s stock price, profit, revenue and ratings have sagged in recent years.

The only thing that hasn’t sagged, it appears, is Dauman’s salary.

In the five years ended in 2015, Dauman has averaged $85 million a year in compensation, one compensation expert told CNBC earlier this year.

Viacom shares are down 32 percent in the last year.

On Wednesday, Sumner Redstone, in a statement, said, “I no longer trust Philippe Dauman or those who support him.”

In addition to Dauman, Redstone announced the removal of independent directors Salerno, George Abrams, Blythe McGarvie and William Schwartz from the company’s board.

Replacements named for the five are: Kenneth Lerer, chairman of BuzzFeed and a co-founder of The Huffington Post; Thomas May of Eversource Energy; Judith McHale of Cane Investments; Ronald Nelson of Avis Budget Group; and Nicole Seligman, former president of Sony Entertainment.

Apparently pleased by the prospect of a Viacom no longer being run by Dauman, investors sent Viacom shares up 6.8 percent, to $45.05.

Ironically, the rise — among the largest one-day gains in recent times — added $3.5 million to Dauman’s net worth.

Redstone’s NAI holds 80 percent of the voting shares in Viacom and CBS.

Redstone owns 80 percent of National Amusements, while Shari owns the remaining 20 percent.