The Hammers went into the game on a run of three successive defeats, while Leicester’s top-seven hopes took a knock last time out when they crashed to a 1-0 home defeat against Newcastle at The King Power Stadium.
The Foxes had won two and drawn one of their three previous games at West Ham, but they found themselves behind eight minutes before the half-time interval when Michail Antonio opened the scoring with a header.
Jamie Vardy grabbed an equaliser in the second half only for Lucas Perez to score what looked like the winner eight minutes from time.
But Barnes grabbed his first Premier League goal in the second minute of added time to rescue the Foxes a point.
The draw takes Manuel Pellegrini’s West Ham side on to 43 points and they remain five points behind the Foxes in eighth.
Manuel Lanzini and Javier Hernandez were replaced by Antonio and Marko Arnautovic as West Ham made two changes to last weekend's unfortunate 2-1 defeat at Manchester United.
Leicester also made two changes after they were beaten by the Magpies eight days ago with Jonny Evans and Mark Albrighton coming in to replace Wes Morgan and Barnes.
West Ham started brightly with Arnautovic going close inside three minutes when he curled an effort just wide of Kasper Schmeichel’s upright, before James Maddison had the Foxes first effort of note a minute later with a drive straight at Lukasz Fabianski.
Moments later, there was a scramble in the Leicester area, but Mark Noble saw his path to goal blocked and Arnautovic’s follow-up effort was denied by the head of Maddison.
Schmeichel got lucky in the 18th minute when his attempted clearance rebounded off Robert Snodgrass but was cleared by a defender before a Hammers player could take advantage.
West Ham created another good opening on 27 minutes when Arnautovic hooked the ball into the area and Antonio seemed put off by Ricardo Pereira as his subsequent effort looped into the hands of Schmeichel.
Maddison had another effort go straight at Fabianski, before Antonio got in the way of a Felipe Anderson effort and deflected wide of the Leicester goal at the opposite end.
However, the Hammers got the opening goal their play warranted in the 37th minute when Noble lifted an excellent cross into the middle and Antonio got the better of Ben Chilwell in the air before powering a header past Schmeichel.
Following a quiet opening to the second half, Noble went close with an effort from distance which bobbled just wide, before Vardy went close at the other end as he just failed to divert a Youri Tielemans cross into the area.
Referee Lee Probert then turned down Leicester appeals for a penalty on 66 minutes when Chilwell went to ground under a challenge from Fabian Balbuena inside the West Ham area.
However, the Foxes levelled a minute later when Vardy got ahead of Fabian Balbuena to convert a Chilwell cross from the left.
The goal visibly lifted Leicester and they went looking for a winner as Wilfried Ndidi curled an effort just wide of the far post, before Balbuena cut out a Maddison pull-back before the striker could grab his second of the afternoon.
But West Ham gradually composed themselves and went back in front on 82 minutes when Pedro Obiang saw his effort crash back off the crossbar into the path of Perez who fired in the rebound from close range.
Leicester pushed in search of an equaliser in the closing stages with Vardy’s ball across the area missed by Barnes and Kelechi Iheanacho, before Balbuena did well to knock a Barnes cross out of play before Iheanacho could get on the end of it.
However, with the clock ticking towards full-time, it was Barnes who snatched a point for the visitors when he latched on to a Tielemans ball into the area and hit his effort across the dive of Fabianksi and into the corner of the net.