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.
City chiefs confirm contractor appointed to lead construction of 'ultra-modern' homes on former Vaux Brewery site
Watch as Sunderland residents are outraged after personal information and photographs left dumped outside of former care home
Farmer who lived a ‘James Bond type fantasy’ and told girlfriend he was in Secret Service jailed after gun found hidden in his chicken coop
Three men in court after brothers assaulted outside Sunderland city centre bar
Reveller needed 22 stitches to his head after shocking Sunderland city centre attack
“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.