Endocarditis is an infection of the inner lining of the heart chambers and heart valves. It occurs when bacteria, fungi, or other germs from another part of the body spread through the bloodstream and attach to damaged areas of the heart. This condition can be life-threatening if not treated promptly.