Lee Gregory pulled one back but Wes Thomas struck late on as Lee Clark's men ended a seven-match winless run and secured a first away success of the season.
Millwall's bright start to the season has evaporated, however, and another defeat leaves them with just one point from a possible 15.
The Lions, stung by criticism from boss Ian Holloway following the "dire" weekend loss at Huddersfield, went straight on the attack and Scott McDonald fired wide inside the first 30 seconds.
Scott Malone then floated in a dangerous cross which on-loan Watford striker Mathais Ranegie nodded just the wrong side of the post.
McDonald squandered another chance when he slid in to meet Ranegie's downward header but again was off target, and the hosts promptly fell behind to Blues' first real chance in the 32nd minute.
Donaldson held the ball up well on the edge of the area and fed Cotterill down the right before ambling unmarked to the six-yard box and tapping the winger's low cross into an empty net.
Eight minutes later Millwall gave away a free-kick 25 yards out and Cotterill's swerving shot deceived Lions goalkeeper David Forde as it bounced into the net to double Blues' lead.
Holloway threw on young striker Aiden O'Brien at the break and the move paid off nine minutes later when his header sent Gregory clear to lift the ball over Darren Randolph for his first Lions goal since signing from non-league Halifax in the summer.
Defender Mark Beevers had a gilt-edged chance to haul Millwall level on the hour when he met Shaun Williams' free-kick with a free header six yards out, but he planted the ball straight at Randolph.
Ranegie then hit the roof of the net with a header, O'Brien's shot was deflected wide and Randolph denied Williams with a fine reaction save as the Lions built up a head of steam during the final 20 minutes.
Beevers was by now playing up front in a five-man attack, but their chances of an equaliser disappeared along with Ricardo Fuller's wayward shot which flew over.
Instead Blues survived the onslaught and wrapped up a much-needed win when substitute Thomas tucked in Cotterill's cross six minutes from time.
Millwall: Forde, Hoyte (Chaplow 46), Dunne, Beevers, Malone, Williams, Abdou, Upson (O'Brien 46), McDonald, Ranegie (Fuller 69), GregoryBold (Ctrl+B)
Subs not used: Woolford, Briggs, Webster, King
Blues: Randolph, Caddis, Edgar, Robinson, Grounds, Cotterill, Davis, Reilly (Packwood 71), Gleeson, Arthur (Thomas 74), Donaldson
Subs not used: Duffy, Hall, Lee, Doyle, Shinnie
Referee: Roger East