Boro are second bottom of the Premier League, three points from safety, with only Sunderland below them.
They haven’t won in the league since beating Swansea City before Christmas, and Karanka has paid for that poor run of results with his job.
Agnew, who made 63 appearances for Sunderland, steps up from assistant head coach to take charge of the first team, and looks set to be in the dugout for the game against Manchester United on Saturday.
A club statement said: “Both parties have agreed that it is in the best interests of the club to make this change.
“The club would like to thank Aitor for all his hard work over the past three and a half years and for the success we’ve had during that time. We wish him all the best for the future.”
Karanka said: “I’d like to thank Middlesbrough for a wonderful opportunity and the players, staff and all the people at the club who I have worked with. I’d also like to thank the fans for their support.
“This club will always hold a special place for me and I wish everyone connected with Middlesbrough Football Club the very best for the future.”
Agnew had a spell as assistant manager at Gateshead, Middlesbrough, Hartlepool and Hull City before returning to Boro as Karanka’s No 2 in 2014.