Both led in the first half, but Gloucester went in up at the break with Marshall and Richard Hibbard scores.
Sam James and Mike Phillips crossed in the first half for Sharks, who went 24-15 ahead with Byron McGuigan's try.
But tries from Henry Trinder, Marshall and Billy Twelvetrees gave the hosts a bonus-point win.
The result left the Cherry and Whites, in eighth, one point off sixth-placed Harlequins.
However, their other top-six rivals Northampton Saints play Saracens on Sunday.
Gloucester had made the early breakthrough at Kingsholm after a neat interchange between England international Jonny May and Marshall but the hosts allowed their opponents two quick tries, James and the soon-to-retire former Wales international Phillips capitalising on lax defence.
Hibbard, though, put the hosts back in front after scoring off a line-out, before the scoreline turned in Sale's favour once more when AJ MacGinty set up Kieran Longbottom for a try and good play from number eight Josh Beaumont out on the wing sent in McGuigan.
But Gloucester pulled clear after Trinder was left with an easy finish, and Marshall touched down his second before Twelvetrees rounded off a superb flowing move.
Gloucester interim head coach Jonny Bell: "I'm delighted with the five points but we always make life difficult by hurting ourselves.
"We scored five excellent tries but we gift-wrapped them three or four easy tries and there were too many fundamental mistakes.
"We've probably played better this season and lost. The replacements made a big impact to get over the line today but there is still plenty to work on."
Sale director of rugby Steve Diamond: "Our aim was to come down here and score four tries, which we did, but we should have had at least another point.
"The second one was taken away from us in the last minute with a penalty but we couldn't see any offside for that penalty to be awarded.
"We are what we are and our position in the table reflects it. Week in week out, we are inconsistent and we are even inconsistent during the course of games."
Gloucester: Marshall; Sharples, Trinder, Atkinson, May; Burns, Braley; Hohneck, Hibbard. Afoa; Thursh (capt), Galarza, Moriaty, Ludlow, Clarke.
Replacements: Matu'u, McAllister, Knight, Savage, Morgan, Vellacott, Twelvetrees, Halaifonua.
Sale: Haley; Solomona, James, Jennings, McGuigan; MacGinty, Phillips; Harrison, Webber, Aulika, Evans, Ostrikov, Neild, B Curry, Beaumont (capt).
Replacements: T Curry, Flynn, Longbottom, Nott, Pearce, Mitchell, Bedlow, Charnley.
For the latest rugby union news follow @bbcrugbyunion on Twitter.

But once the votes are counted, what can residents expect to pay in council tax?
Below are the figures for a Band D property for every council area in Wales for the current financial year of 2017/18, how much that has gone up by for the current year, and what the average property in the area actually pays.
They are grouped here by police force region - council tax includes the police precept which is added to the overall bill paid by homes.
Local government is not fully funded by council tax.
Much of the funding for councils comes in the form of grants from the Welsh Government, which in turn gets its funding from the UK government in London.
In 2017/18 a total of £4.1bn is being divided among Wales' 22 councils.
The lions share of council cash goes on schools - with social services following behind, as shown in the graph above.
Residents pay council tax based on which band their property is in, based on its worth. Band D has historically been used as the standard for comparing council tax levels between and across local authorities.
It is used to charge tax to a property that, in Wales, was worth between £91,001 to £123,000 on April 2003 values. Council tax gets lower the cheaper a property is, and higher the more expensive a property is.
Council tax figures source: Welsh Government
Tom Marshall scored two tries to help Gloucester maintain their hopes of a top-six finish with victory in a thrilling encounter with Sale Sharks.
[NEXT_CONCEPT]
Voters will go to the polls on Thursday to determine who will represent them on local councils.