NEW YORK — The Boston Celtics won the NBA draft lottery Tuesday night, capitalizing on a trade they made with the Brooklyn Nets four years ago.

The Los Angeles Lakers were the other big winners, moving up one spot to second to hold onto their pick. They would have had to trade it to Philadelphia if it fell outside the top three.

The Celtics will go from No. 1 seed to No. 1 pick after their 25 percent chance of winning came through. They beat Washington in Game 7 of the second round Monday and open the Eastern Conference finals at home Wednesday against Cleveland.

“It’s two completely different situations: One is a lot about the future and one is in the present,” said the Celtics’ president, Danny Ainge. “This team is a lot of fun to be around this year.”

Brooklyn finished with the worst record in the league but the Celtics had the right to swap picks from the 2013 draft-night trade that sent Kevin Garnett and Paul Pierce to the Nets.

The 76ers will pick third and Phoenix fell two spots to fourth.

“I’m excited,” 76ers rookie center Joel Embiid said. “We jumped up one more spot. I wish we would have gotten the No. 1 pick but we trust the process and it’s going to be exciting to see what we’re going for.”

The Celtics were going to be in prime position no matter how the Ping-Pong balls bounced in a hotel ballroom. They were guaranteed no worse than the No. 4 pick to add to a team that had the best record in the East this season. And they still get one more first-round pick next season from the Nets, who likely will miss the playoffs again.

Boston acquired the Nets’ 2014, 2016 and 2018 first-round picks in the deal.

Their victory made it three straight years the team with the best odds won the lottery after going the previous decade without a victory. Minnesota snapped that streak by getting the eventual Rookie of the Year, Karl-Anthony Towns, in 2015 and Philadelphia emerged with Ben Simmons last season.

The draft is considered a strong one, loaded with point guards such as Markelle Fultz, Lonzo Ball and De’Aaron Fox.

And the Lakers will get a chance to take one of them after beating the odds to move up in their first year with Magic Johnson as team president. They had about a 53 percent chance of falling out of the top three, which would have triggered a trade of the pick as remaining payment of their acquisition of Steve Nash in 2012.

Not only that, but they would have had to trade their 2019 first-round pick to Orlando if that happened, so Johnson was all smiles even after finishing behind Boston. A late five-game win streak by his young team damaged its odds by falling behind Phoenix for the second-worst record in the league.

“You see, you don’t know what’s been going on in L.A. They’ve been like ‘Oh my god, we blew it,’ ” Johnson said. “We won five in a row and everybody thought we were crazy. So now the fans back home can breathe a little easier.”

Sacramento moved up into the top three, but the 76ers had the right to swap with them through a past trade. The Kings will select fifth and 10th.

Orlando is sixth, followed by Minnesota and New York.