It went from euphoria to anger quickly at Barclays Center.

Just as it looked like center Jahlil Okafor might fall to the Knicks at No. 4 in Thursday’s NBA draft, the Duke center got snapped up by Philadelphia, leaving Phil Jackson to roll the dice on a project.

Unable to trade down and gain a second asset, he decided to gamble on the skinny, 7-foot-3 project from Latvia, 19-year-old sharpshooter Kristaps Porzingis. (The Knicks decided to list him at 7-3, though he was designated at 7-1 in Europe, where he was measured without shoes).

While sources indicated the Knicks still could be open to trading him, he’s here for now.

“The reward is great, the risk is great, too,” Jackson said.

The Spanish Leaguer may have the highest upside outside No. 1 pick Karl-Anthony Towns because of his 3-point shooting ability, but is considered two years from making an impact and could be a major liability on defense. The Knicks had shopped the pick but did not come close to a deal.

After making the pick, Jackson said he would monitor the rest of the draft, hoping to do more, and did so by trading for the rights to a prospect who could make an immediate impact in Notre Dame senior point guard Jerian Grant. But Jackson had to trade 2013 first-rounder Tim Hardaway Jr., who had a disappointing second season. Nevertheless, the Grant addition made the Porzingis selection more palatable to the fans who cheered the announcement.

Predictably, the fans at Barclays Center booed the first pick mercilessly.

“A lot of fans weren’t happy they drafted me,” Porzingis said. “I have to do everything that’s in my hands to turn those booing fans into clapping fans. There’s nothing I can do. I was happy about it. I want to be part of this organization. Fans are a little bit harsh sometimes, but that’s how it is in New York and I’m ready for it.”

Jackson thinks Porzingis has the mental makeup to handle the fans’ wrath and the skill for the triangle offense.

“I think our fans are going to like him,’’ Jackson said. “The reaction in the crowd is what you anticipate in New York, but he’s aware of it. He’s very much intelligent. He’s going to face an uphill battle but he’s willing to take it on.”

“We want to believe that [he can be the best player in the draft in 10 years]. We like the fact it was a choice for us. He has the intestinal fortitude to go after it.’’

Jackson said Porzingis had the “greatest risk and reward’’ of anyone in the draft, but wasn’t sure about his immediate impact.

“Our coaching staff’s concern with any young players is how they will defend,’’ Jackson said. “This is a big question about this young man, how he will fit out on the court and defend. The learning process is going to be defensively.

“We know it might take a year, but he’s willing to work and he’s got the equipment to do it.”

Jackson had not met Porzingis until Monday, but Knicks European scout Kevin Wilson is based in Spain, where Porzingis played for Seville. Wilson campaigned heavily for Porzingis.

“For me, it’s a dream come true to play for the Knicks,” Porzingis said. “I wanted to see myself in this situation. Now it’s here. I can’t wait to be part of this organization and get to work.”

If the Knicks couldn’t trade down, they considered heavily taking point guard Emmanuel Mudiay. But he, too, is 19 and may not have made an impact as a rookie, the team decided.

According to a source, even Carmelo Anthony supported the Porzingis risk and watched the Spanish Leaguer’s workout Monday. However, the workout ended when it was cut short by cramps.

“You do what’s best for this franchise in this particular time in history of where we’re at,’’ Jackson said. “We have five players on the roster and needed something athletic to make a real difference in the way we play. This young man is an eye-opening athlete and a player.’’

Jackson compared him to his former Laker big man Pau Gasol.

“Pau was a 7-footer who made great contributions to our teams in L.A.,’’ Jackson said. “This young man has better range, but that’s the evolution of the game at this time. There’s a lot of comparisons to him. Their bodies are similar and the activity level on how they run is similar and athleticism is similar.’’

Meanwhile, a sure thing in Okafor nearly fell to No. 4. The topsy-turvy draft continued its turns as the Lakers took guard D’Angelo Russell over the presumptive favorite Okafor. That was supposed to toss Okafor to the Knicks as the Sixers reportedly would take Mudiay. But the Sixers spoiled the celebration by taking Okafor.

Still, the fans chanted “Let’s go Knicks’’ as commissioner Adam Silver stepped to the podium. At the sound of “Porzingis,” however, it quickly turned to boos and anger lasting through his TV interview.