Jamie Vardy's crisp finish from a lightning break gave Leicester the lead on 18 minutes - but he was then sent off after getting a second yellow card for diving when he tangled with Angelo Ogbonna early in the second half.
Referee Jonathan Moss made himself even more unpopular when he awarded West Ham a penalty with six minutes left. There had been pushing and pulling in both penalty areas but he decided to punish Wes Morgan for pulling back Winston Reid at a corner.
Analysis: MOTD2 pundits on referee's 'mind-boggling inconsistencies'
Substitute Andy Carroll slotted home to end Leicester's run of 574 minutes without conceding a league goal and Aaron Cresswell looked to have opened the door to the Foxes' title rivals Spurs with a stunning left-footed finish two minutes later.
As the game went into injury time, Moss produced another controversial decision when he pointed to the spot once more after Carroll made the merest contact with Jeff Schlupp.
West Ham clearly felt Moss had evened things up after earlier decisions in their favour, but Ulloa was not concerned as he took the chance to secure what might yet be a vital point - although Leicester will be without Vardy for next weekend's home game with Swansea.
Relive the action from the King Power Stadium
Leicester's fans celebrated at the end before turning their anger on referee Moss - although it was his very questionable decision that allowed them to earn that point at the end.
Psychologically, this point could be vital because a loss might just have produced a few doubts and given Spurs just a little more wiggle room going into their game at Stoke on Monday.
It means Leicester's last Premier League defeat is still that last-minute loss at Arsenal on Valentine's Day and their spirits will be lifted by the manner in which they earned a point when it seemed certain they would end up empty-handed.
Referee Moss was surrounded by players of both sides and escorted from the field by stewards to jeering from the home fans at the final whistle.
Moss's eventful second half began after 56 minutes when he penalised Vardy for simulation as he tumbled theatrically under a challenge from Ogbonna. Having already given Vardy a yellow card, he felt obliged to give a second.
Vardy made the most of the contact and ran the risk of punishment. And he has been accused of doing this before this season. Opinion was split but plenty felt Moss was right.
For West Ham's penalty, there was undoubtedly pulling and pushing between Morgan and Winston Reid - so again Moss had justification.
The difficulty, the inconsistency, is that similar behaviour had been going on in both penalty areas all afternoon without punishment - so why did Moss decide this was the time to penalise it?
Too often, these decisions seem arbitrary, as was demonstrated when Ogbonna dragged Huth to the floor even more unceremoniously a few minutes later and no foul was given.
Finally, in injury time and with an atmosphere of chaos engulfing the game, Moss pointed to the spot for the slightest touch from Carroll on Schlupp. It was incredibly harsh and the Hammers clearly felt Moss had punished them to make up for earlier decisions given against Leicester.
It is a tough job - as the abuse directed the referee's way at the end proved.
Not as much as there might have been had Ulloa not scored at the end, but they can apply pressure and move to within five points of Leicester if they win at Stoke.
Leicester at least have the point in the bag but Mauricio Pochettino and his players will just feel the door is ajar, even if they know time and games are running out.
Leicester boss Claudio Ranieri: "It was a very tough match. We were lucky at the beginning when they touched both posts. After that we scored a great goal and we had an opportunity to finish the match at the beginning of the second half.
Media playback is not supported on this device
"After then sending off it changed our match.
"I never spoke about the decision of the referee. Two yellow cards, that's it.
"Our performance 11 v 11 and 10 v 11 was fantastic."
West Ham manager Slaven Bilic: "It was a good game of football. We showed determination, character and quality. We turned the game around. We were dangerous, and after sending off we totally dominated the game.
Media playback is not supported on this device
"After our second goal I thought we had done enough to win the game, maybe we could have coped with added time better in terms of keeping the ball but they took the risk.
"It was extremely hard for referee, but I mean that was no penalty at all."
Leicester - minus the suspended Vardy - are at home to Swansea next Sunday. The Hammers host Watford on Wednesday.
Match ends, Leicester City 2, West Ham United 2.
Second Half ends, Leicester City 2, West Ham United 2.
Goal!  Leicester City 2, West Ham United 2. Leonardo Ulloa (Leicester City) converts the penalty with a right footed shot to the bottom right corner.
Penalty conceded by Andy Carroll (West Ham United) after a foul in the penalty area.
Penalty Leicester City. Jeffrey Schlupp draws a foul in the penalty area.
Offside, Leicester City. Danny Simpson tries a through ball, but Leonardo Ulloa is caught offside.
Manuel Lanzini (West Ham United) wins a free kick in the defensive half.
Foul by N'Golo Kanté (Leicester City).
Attempt missed. Emmanuel Emenike (West Ham United) right footed shot from outside the box misses to the left.
Attempt missed. Robert Huth (Leicester City) header from the centre of the box misses to the right. Assisted by Christian Fuchs.
Foul by Andy Carroll (West Ham United).
Leonardo Ulloa (Leicester City) wins a free kick in the attacking half.
Foul by Angelo Ogbonna (West Ham United).
Leonardo Ulloa (Leicester City) wins a free kick on the right wing.
Goal!  Leicester City 1, West Ham United 2. Aaron Cresswell (West Ham United) left footed shot from the left side of the box to the top right corner.
Goal!  Leicester City 1, West Ham United 1. Andy Carroll (West Ham United) converts the penalty with a left footed shot to the bottom right corner.
Penalty West Ham United. Winston Reid draws a foul in the penalty area.
Penalty conceded by Wes Morgan (Leicester City) after a foul in the penalty area.
Corner,  West Ham United. Conceded by Wes Morgan.
Attempt missed. Enner Valencia (West Ham United) right footed shot from the centre of the box misses to the left. Assisted by Cheikhou Kouyaté.
Attempt missed. Cheikhou Kouyaté (West Ham United) header from the centre of the box misses to the right. Assisted by Aaron Cresswell with a cross.
Enner Valencia (West Ham United) wins a free kick in the defensive half.
Foul by Jeffrey Schlupp (Leicester City).
Attempt missed. Dimitri Payet (West Ham United) right footed shot from outside the box is too high from a direct free kick.
Substitution, Leicester City. Daniel Amartey replaces Riyad Mahrez.
Wes Morgan (Leicester City) is shown the yellow card for a bad foul.
Andy Carroll (West Ham United) wins a free kick in the attacking half.
Foul by Wes Morgan (Leicester City).
Corner,  West Ham United. Conceded by N'Golo Kanté.
Attempt missed. Emmanuel Emenike (West Ham United) right footed shot from outside the box is just a bit too high.
Substitution, West Ham United. Enner Valencia replaces Victor Moses.
Hand ball by Aaron Cresswell (West Ham United).
Foul by Winston Reid (West Ham United).
Leonardo Ulloa (Leicester City) wins a free kick in the defensive half.
Attempt missed. Manuel Lanzini (West Ham United) right footed shot from outside the box is just a bit too high. Assisted by Dimitri Payet.
Substitution, West Ham United. Manuel Lanzini replaces Mark Noble.
Winston Reid (West Ham United) hits the right post with a right footed shot from very close range. Assisted by Dimitri Payet with a cross following a corner.
Corner,  West Ham United. Conceded by Robert Huth.
Substitution, Leicester City. Leonardo Ulloa replaces Shinji Okazaki.
Foul by Michail Antonio (West Ham United).
Leonardo Ulloa's injury-time penalty rescued a point for Leicester in a controversial encounter with West Ham as the Foxes went eight points clear at the top of the Premier League.