The Los Angeles Lakers have agreed to terms with center Deandre Ayton on a free agency contract, pairing the former No. 1 pick with the player taken two spots behind him in 2018 — Luka Dončić, team and league sources confirmed to The Athletic.

The deal is for two years and $16.6 million, with a player option for the second season, according to league sources. The Lakers will pay him $8.1 million — the remainder of the midlevel exception after accounting for free agent Jake LaRavia’s salary — in 2025-26.

Ayton spent the past two seasons with the Portland Trail Blazers after being dealt by the Phoenix Suns in the deal that sent Damian Lillard to the Milwaukee Bucks. In Portland, Ayton played in only 95 games, averaging 15.7 points, 10.7 rebounds, 1.6 assists, 0.9 blocks and 0.9 steals.

Ayton was a surprise addition to this year’s free agency class, negotiating a contract buyout with the Trail Blazers on Sunday night and surrendering a reported $10 million of a $34 million deal. Ayton and Dončić are both represented Bill Duffy, the longtime agent who heads WME Basketball.

Dončić, according to league sources, is excited about the opportunity to play with Ayton.

The Lakers, according to team and league sources, showed serious interest in veteran center Brook Lopez, who agreed to a two-year deal with the LA Clippers on Monday. He was pegged by many around the NBA as the logical player for the Lakers this free agency cycle. Lopez, 37, is still one of the NBA’s best inside-outside centers but doesn’t play the kind of pick-and-roll, lob-threat style that Dončić has had the most success with in his career.

Ayton, who turns 27 at the end of July, will have plenty to prove after being traded out of Phoenix and released by the Trail Blazers. Viewed as an unquestioned talent, questions about consistent motivation and defensive capabilities have overshadowed much of Ayton’s offensive ability.

The Bucks were interested in Ayton, according to league sources, before they shocked the NBA by acquiring Myles Turner from Indiana. The Pacers, who once signed Ayton to a restricted free agency contract that the Suns matched, also checked in on the former No. 1 pick.

The signing answers the biggest question heading into the Lakers’ summer — who will play center? The Lakers finished last season by benching starter Jaxson Hayes for the final six quarters of their season against the Minnesota Timberwolves.

More questions, though, have been asked since LeBron James opted into his deal, with his agent, Rich Paul, telling The Athletic, “LeBron knows the Lakers are building for the future, and he also wants to compete for championships. We understand the difficulty in winning now while preparing for the future. We do want to evaluate what’s best for LeBron at this stage in his life and career.

“He wants to make every season he has left count, and the Lakers understand that, are supportive and want what’s best for him. We are very appreciative of the partnership that we’ve had for eight years with Jeanie (Buss) and Rob (Pelinka) and consider the Lakers as a critical part of his career.”

That remains unsettled.

But the Lakers’ top free agency priority — finding a big — can be checked off their list.

(Photo of Deandre Ayton: Meg Oliphant /Getty Images)