The diaphragm separates the thoracic cavity, containing the heart and lungs, from the abdominal cavity and performs an important function in respiration.