Bob Harper -- a fitness guru who's the host of "The Biggest Loser" -- suffered a heart attack that left him unconscious for 2 days.

Harper tells us he was working out in a NYC gym 2 weeks ago when he collapsed. A doctor who was also working out administered CPR and used paddles to keep Bob alive.

The 51-year-old was taken to the hospital and says he woke up 2 days later. He was hospitalized for 8 days and is still in NYC -- he lives in L.A. -- because his doctors have not cleared him to fly.

He's doing a lot better and his exercise for the time being is limited to walking.

Bob -- a fitness nut -- says the heart attack is all genetics. His mom died from a heart attack.

Glad he's on the mend.