Australia all-rounder Marsh is ruled out for at least the start of the county campaign due to an ankle injury that requires surgery.
Elgar will therefore join Surrey ahead of their County Championship opener against Hampshire next Friday.
The batsman, who has amassed 3,194 runs with 11 centuries at an average of 42.58 in 49 Tests for the Proteas, will be absent for the four-day clash against Worcestershire next month due to a prearranged commitment.
But the 30-year-old will be in contention for Surrey’s three other fixtures in the championship and five in the One-Day Cup before the start of June.
Elgar, who had a stint at Surrey three years ago, said on the county’s official website: “I am really grateful for the opportunity to be back at Surrey for the start of the summer.
“I hope to contribute for the period I am at the club, on and off the field, and I’m looking forward to seeing all involved at the great club again.”
Director of cricket Alec Stewart added: “Given the news that Mitch Marsh will need ankle surgery, to be able to bring someone of Dean’s calibre to the club, at such short notice, for the first period of the season is a real bonus.
“We know Dean well after his time with us in 2015 and his international quality and experience will be a real asset.”
— Surrey Cricket (@surreycricket) April 12, 2018
Provided by Press Association Sport
Know more about Sport360 Application