The gunman who killed three people at California’s Gilroy Garlic Festival is a local teen who apparently posted a final message praising a notorious hate-filled extremist book before the slaughter.

Santino William Legan, 19, was identified by police sources Monday as the gunman who also injured 15 in Sunday’s carnage before being shot dead by cops, according to numerous media outlets including the Associated Press.

An Instagram account holder using the same name and age, calling himself “Italian Iranian,” had just three posts and went offline soon after he was first identified as the killer.

It featured a picture from the garlic festival before the carnage — as well as praise for what has been called “one of the most incendiary works ever to be published anywhere.”

“Read Might Is Right by Ragnar Redbeard,” the account wrote next to a photo of a Smokey the Bear sign warning, “Fire danger high tonight.”

He was referring to a much-hated 1890 book embraced by white supremacists that was banned for years after being condemned as sexist, racist and anti-Semitic.

“Why overcrowd towns and pave more open space to make room for hordes of mestizos and Silicon Valley white twats?” the Instagram message continued, using a Hispanic slur for people of mixed race.

Before that, he posted a photo from inside the garlic festival.

“Ayyy garlic festival time. Come get wasted on overpriced s–t,” the account stated next to a view of the festival.

Police recovered his backpack along with a rifle and ammunition, CBS said, with officers having already searched his home as well as a second property.

A local newspaper profile two years ago said his family — including three brothers — were all boxers whose dad, Tom Legan, a keen athlete, coached them out of a home gym.

Gilroy Police Chief Scott Smithee said the gunman used “some sort of tool” to cut a fence and sneak into the event, avoiding metal detectors at security checkpoints.

He appeared to randomly target people when he opened fire just after 5:41 p.m. Sunday, Smithee said.

Legan killed three, including 6-year-old Stephen Romero, whose mom and grandmother were among 15 injured. Witnesses say he shouted out that he was “very angry” during his killing spree.

He was then shot dead by cops who engaged him within a minute of the first shots ringing out, Smithee said.

“It’s sort of a nightmare that you hope you never have to live in reality,” the police chief said.

California Gov. Gavin Newsom called the attack “nothing short of horrific.”

President Trump on Monday called it a “wicked murder” and said, “We grieve for their families….we’re praying for those who are recovering right now in the hospital.

“We will continue to work together as communities … to stop evil.”

Sunday was the end of the three-day Gilroy Garlic Festival, which attracts more than 100,000 people to the city known as the “Garlic Capital of the World.”