MIAMI — They came to the Miami Heat a year ago almost as afterthoughts, two guys with less-than-stellar reputations who didn’t exactly have an abundance of options.

Those days are long gone for James Johnson and Dion Waiters.

They’re now cornerstones of Miami’s plan to return to contention.

Capping several days of salary-cap maneuvering to make sure all the pieces fit the right way, the Heat announced the signings of Johnson, Waiters and newcomer Kelly Olynyk on Friday (Saturday in Manila) to new four-year contracts. All were agreed upon earlier this week, though Miami didn’t start closing those deals until more cap space was created earlier in the day by trading Josh McRoberts to Dallas.

Combined, Johnson, Waiters and Olynyk’s deals have a maximum value of about $165 million. Those three played for $10 million last season.

“As soon as Kelly Olynyk became an unrestricted free agent, we pursued him,” Heat President Pat Riley said. “He is not only a post player, he can also play away from the basket. What we like the most is that he is a playmaker, tough defender and rugged rebounder. At just 26 years old, he fits in perfect with our young core that will play together in their primes.”

Olynyk thinks he and Miami will be a great fit.

“The culture here, I’ve heard so much about it,” Olynyk said. “I’m really excited about it.”

Olynyk being added to the mix was the lone surprise.

Johnson and Waiters had made clear they wanted to stay in Miami long ago.

Johnson was courted by the Utah Jazz after Gordon Hayward left for Boston and said he was still getting used to the idea of being a sought-after commodity.

“It was my first time ever being in a situation like this,” Johnson said on Friday night (Saturday). “Everything was mind-boggling and exciting at the same time. I was just riding the rollercoaster.”

As intoxicating as it was, he had so many reasons to stay.

Johnson could make over $60 million in the next four seasons, a huge bump from the $4 million he played for last season. He dropped 40 pounds, changed his body, changed his outlook and went from someone who bounced around the league — and carried a bit of an underachiever label — to someone Miami trusted to have on the floor at the end of games last season.

“It’s not just what they did for his game, it’s what they did for his life,” said Mark Bartelstein, Johnson’s agent. “When you look at where he was a year ago and where he is now, it’s an amazing story and it’s been a great marriage there between James and the Heat.”

Heat guard Wayne Ellington — whose $6.3 million team option for next season is set to become officially picked up at midnight Saturday — said Johnson’s payday was both inspiring and well-deserved.

“Congratulations to my guy J on his new deal!” Ellington wrote on social media. “We came in to the league together and I watched your journey and your transformation!”

“Not only does Miami want me back,” Johnson said, “but my guys want me back as well.”

Waiters transformed as well.

He slimmed down at the team request, and his game took off — making him a go-to player in Miami last season.

“Dion was so important to us,” Heat point guard Goran Dragic said. “He worked hard and you saw what that did for his game.”

Much of the space Miami used this summer was created by the waiving of Chris Bosh, who still gets his $25.3 million salary for this season but doesn’t have it count against the Heat books. The Heat went after Hayward and lost out when he picked Boston, so that meant Miami went to what Riley described as Plan B: keeping its own guys.

Waiters was the first big domino to fall Miami’s way in that plan, agreeing to his deal on Wednesday. Johnson and Olynyk agreed on Thursday.

Waiters averaged 15.9 points on 42 percent shooting last season, but his effect on Miami’s success was clear simply in won-lost numbers. When he played, the Heat won 59 percent of their games — a rate that would have been good enough for a No. 5 seed in the Eastern Conference. When Waiters didn’t play, Miami won only 39 percent of the time.

“This is where I want to be,” Waiters said earlier this summer.

It’s where he’ll be for a while now.