Shrewsbury started the second half on top, as they had done the first, and it was Lloyd who again played a pivotal role when, following a sloppy interchange, he drew a foul from defender Eoghan O'Connell to win a penalty.
Marquis was denied with his initial attempt, but made no mistake with the rebound when it fell kindly to him.
The Welsh side were almost level for a second time with 10 minutes to play, when another excellent cross from Barnett was met by substitute Paul Mullin, but two fine blocks and a Jamal Blackman save later, the danger was averted.
Shrewsbury move up to 21st with victory, within five points of safety, having taken another big home scalp in Wrexham, just as they did when they raised their game to beat Birmingham City in boss Gareth Ainsworth's first game in charge, but they also prevented their border rivals from going top of League One.
Instead Wrexham remain third, two points behind leaders Birmingham, having now played three more games than Blues.