The Dragons, who face next season in the Blue Square Premier, edged in front after 11 minutes when a free kick from Wes Baynes was headed in by Levi Mackin.
Wrexham kept up the pressure and after Lincoln’s Gary Croft handled on the edge of the box, Baynes blasted home a free kick in the 33rd minute.
Lincoln pulled a goal back two minutes before the break when Lee Beevers thumped a 40-yard clearance deep into the Wrexham half, but keeper Gavin Ward and centre-back Steve Evans managed to make a complete hash of clearing, with Evans heading the ball into his own net.
But in a dramatic finale Baynes smashed home an 87th minute free kick, sparking a pitch invasion from the visiting fans.
In stoppage time Wright fired in his 15th goal of the season for Lincoln and the Imps almost levelled, before Chris Llewellyn broke away in the third minute of time added on to score Wrexham’s fourth.