Former “Silicon Valley” star T.J. Miller got so mad when a woman rebuffed his drunken flirting on an Amtrak train that he made a bogus 911 call saying she had a bomb in her bag, federal authorities said on Tuesday.

Miller’s alleged prank prompted a massive police response, caused hours of delays and landed him in federal custody Monday on charges that carry up to five years in prison.

The drama started almost as soon as Miller (inset), 36, got onto Amtrak train No. 2258 in Washington, DC, on March 18.

A worker on the train said he looked tipsy as he took his seat in first class and continued to drink — downing two glasses of wine and two double scotch and sodas, the feds said. He flirted with a female passenger who rebuffed his “social overture” by glaring at him, court papers say.

“[Miller] directed a comment to her about her hair; the comment was unwelcome, and she turned to look at Miller in a non-friendly manner,” the complaint says.

Miller barked back at her, saying, “What are you lookin’ at?”

At some point later, they got into a “screaming match.”

Miller — “motivated by a grudge” against the woman — called 911 and reported a female passenger on a train with “a bomb in her bag,” federal officials said.

To compound the problems, the inebriated Miller gave the 911 dispatcher an incorrect train number, prompting police to stop the wrong locomotive — one traveling in Westport, Conn.

A bomb squad found no device, but massive delays were caused.

When investigators called Miller’s phone number, he was no longer on the train because he had been kicked off in New York for being too drunk, officials said.

T.J. Miller (center) and the cast of “Silicon Valley”HBO

He still maintained, however, there was a woman with a bomb, telling cops she kept checking her bag without taking anything out. “I am worried for everyone on that train,” Miller told police, according to court papers. “Someone has to check that lady out.”

Investigators then searched the train Miller had been on — again in Westport — and found no explosives.

The FBI arrested Miller on Monday night as he arrived at La Guardia Airport from Canada.

The comedian and actor was charged with intentionally conveying to law enforcement false information about an explosive device on a train.

After appearing before a judge at a New Haven federal courthouse on Tuesday, Miller — a Denver native living in New York — was released on $100,000 bond.

He refused to comment when reached by The Post.

It was announced last year that Miller would not return for the fifth season of “Silicon Valley.”

He left amid concerns over his use of drugs and alcohol, according to New York magazine. He denied claims in the article that he was too inebriated too work.