The Seattle Mariners, who are in the thick of a crowded American League wild card race, acquired veteran reliever David Phelps from the Miami Marlins.

In exchange, the Marlins received minor leaguers Brayan Hernandez, Pablo Lopez, Brandon Miller and Lukas Schiraldi. Miami continues to re-tool amid the selling of the franchise.

“David was a target player for us headed into the deadline period,” Mariners GM Jerry Dipoto said in a written statement. “The quality of his work, particularly over the past two years in the bullpen, in addition to his versatility (including his background as starter) made him very attractive to us. He fits our roster very well and is controllable through the 2018 season.”

In 44 appearances, Phelps served as Miami’s setup man for A.J. Ramos and accumulated a 3.45 ERA with a 1.34 WHIP and 18 holds in 47 innings. He is not eligible for free agency until after the 2018 season.

The Mariners (48-48) are just 1 1/2 games behind the New York Yankees for the second wild card spot, but also trail the Minnesota Twins (48-46) and have four teams within two games of them.