Malan, 32, played three Tests against England in 2019-20 and was part of Warwickshire's County Championship-winning side last summer, averaging 37.66 across his six appearances for them.
He will be available to play in the Championship and the Royal London Cup, with Jason Behrendroff, Chris Green and Mujeeb Ur Rahman splitting the club's two overseas slots for the T20 Blast.
"I'm very excited to be joining Middlesex," Malan said. "They are without a doubt one of the most prestigious counties and being based at Lord's makes this an incredible opportunity that I'm hoping to grab with both hands."
"We are thrilled to have secured Pieter's signature for the rest of this season," Alan Coleman, Middlesex's head of performance, said. "He will add a huge amount of experience and quality to our batting ranks. As a batter he is vastly experienced, will be a real asset to the dressing room, and we can't wait to welcome him into the club."
Handscomb left the club early in order to join up with the Australia A squad in Sri Lanka and will return home after on parental leave for the birth of his first child. Tim Murtagh will take over as captain in 50-over and four-day cricket.
"I'm a little bit disappointed with how I've gone over here with the bat," he told Middlesex's YouTube channel. "I set high standards and it's quite obvious that I didn't quite make the runs that I wanted to make over here but it's great to see the way they're going about it."