MINNEAPOLIS — When the Minnesota Timberwolves initially agreed to terms with shooting guard Kevin Martin last week, they were still left looking for a versatile, defensive-minded swingman that could help them make up for the loss of the departed Andrei Kirilenko.

They were all set to introduce Martin, a free-agent signing from Oklahoma City, at a press conference Wednesday morning until the door opened at the last minute for them to address the need for perimeter defense and energy. Timberwolves President Flip Saunders turned one free-agent signing into a sign-and-trade deal that is helping them bring Corey Brewer back to Minnesota.

The Timberwolves will send guard Luke Ridnour to Milwaukee as part of a three-team deal with Oklahoma City getting a trade exception worth about $7 million, a person with knowledge of the negotiations told The Associated Press on Wednesday night. The person requested anonymity because the deal has not been officially announced. Martin's deal, a four-year contract worth nearly $30 million, remains the same as the one he agreed to last week and Brewer will get a three-year deal worth $15 million.

The Timberwolves had to send out Ridnour and his expiring contract, worth $4.3 million, to make room for Brewer. Because of complex rules in the new collective bargaining agreement, the Timberwolves have to complete the trade and have Martin and Brewer sign their contracts to push them over the salary cap before they can re-sign swingman Chase Budinger, who agreed to a three-year deal worth $18 million last week, and restricted free agent center Nikola Pekovic, who is still mulling an offer from the Wolves.

Brewer was drafted by the Timberwolves seventh overall in 2007. He spent most of his first four seasons in Minnesota before being jettisoned by former Wolves president David Kahn. Brewer emerged as a difference-maker in Denver last season, averaging 12.1 points and 1.4 steals. He's not the four-position stopper that Kirilenko is, but after the Russian decided to opt out of his $10.2 million deal for next season, the Wolves were forced to look elsewhere to add desperately needed perimeter shooting to the NBA's worst-shooting team last year.

Martin addresses that need in a big way. He hit a career-high 42.6 percent of his 3-pointers in a reserve role for the Thunder last season, but was looking forward to resuming a featured role and once again playing for Timberwolves coach Rick Adelman. The 30-year-old Martin played under Adelman in Sacramento and Houston and enjoyed the best years of his career in Adelman's corner offense.

The 6-foot-7 Martin averaged 14.0 points last season after coming to Oklahoma City in the trade that sent James Harden to the Rockets. He will be a starter again in Minnesota, but the key for him will be recapturing his knack for getting to the free throw line. Once one of the very best in the league at drawing fouls and racking up points at the line, Martin's average attempts per game dropped from 8.4 in 2010-11, his last year playing for Adelman, to 4.5 in his only year under Rockets coach Kevin McHale and 3.2 last year in Oklahoma City.

The Wolves have agreed to terms with Budinger to ensure that they have a better allotment of shooters around point guard Ricky Rubio next season. And while Brewer shot less than 30 percent from 3-point range last year, he will also be relied upon to bring energy in transition and handle the toughest defensive assignments on the perimeter for a team that figures to struggle to stop teams next season.

Kirilenko filled that role superbly last season and was the biggest reason the Wolves improved from one of the worst defensive teams in the league to one that was in the middle of the pack. Adelman used him to guard every position from point guard to power forward, but he also missed 18 games because of injuries. Brewer has proven to be very durable in his six-year career, ever since he missed most of his second season with a knee injury.

Timberwolves fans openly lamented watching him become a key cog in Denver's terrific regular season last year. Filling the exact role he was drafted out of Florida to fill in Minnesota, Brewer raced up and down the court in former Nuggets coach George Karl's free-wheeling offensive system and teamed with Andre Iguodala to give Denver two strong defenders on the perimeter who could create turnovers and get out in transition.

To make it happen, though, the Wolves had to part with Ridnour, a highly respected veteran in a deal first reported by ESPN. The 6-foot-2 Ridnour has spent most of the last two years playing shooting guard, and was a favorite of Adelman's for his competitiveness and willingness to take on bigger players.

Ridnour spent the last three seasons in Minnesota and will return Milwaukee, where he spent two years from 2008-2010.