Grant Leadbitter skippered the Boro side as boss Tony Pulis took the chance to give more of his squad welcome pre-season action.
Boro were in front in the 13th minute after good work from Lewis Wing on the left flank, before he sent over a fine cross for unmarked ex-Sunderland loanee Ashley Fletcher to head home.
Harry Chapman shot over Rochdale’s bar before Britt Assombalonga was denied by a fine Josh Lillis save after a lightning quick Boro break.
Lillis keput out another Assombalonga effort before Chapman doubled the lead early in the second half, firing low into the net after an inch-perfect ball from Fletcher.
Rochdale got one back in the 68th minute as Calvin Andrew rose to head home a right-wing cross.
Brad Inman equalised from close range on 85 minutes, then League One Dale snatched victory in the final minute, with Oliver Rathbone converting at the second attempt after a fine save by sub keeper Connor Ripley.
Boro first-team coach Jonathan Woodgate told mfc.co.uk: “I don’t like losing, my message in the dressing room was as simple as that.
“Friendly game or not, we need that winning mentality.
“It’s a big lesson for me and it’s a big lesson for the younger players.
“You can be the best player on the pitch for 86 minutes, but you make one mistake and you can be the worst – that’s what some of the younger players need to learn.
“They need to learn it quickly because when they do start going out on loan, it’s a man’s game and it’s totally different. But there were some excellent performances as well.”
Boro’s final friendly is at home to Sunderland on Friday.
Rochdale: Lillis, Ntlhe, McGahey, Williams, Andrew, Williams, Thompson, Perkins, Adshead, Cannon, Henderson. Subs: Rafferty, McNulty, Camps, Rathbone, Wilbraham, Inman, Finnerty, Morley, Wade, Gillan.
Middlesbrough: Konstantopoulos (Ripley 46), Mahmutovic, Wood, Fry, Johnson, Leadbitter, De Sart (Liddle 81), Wing (Pattison 67), Fletcher (Walker 74), Chapman (Cooke 60), Assombalonga (Spence 80). Sub: Braithwaite.