Endocarditis is a disease that occurs when bacteria or other microorganisms infect the heart. This can happen after surgery, after an injury, or as a result of another disease. Heart infection can be life-threatening if it is not treated quickly and effectively.