Methylene blue is used medically to treat methemoglobinemia, a condition in which there is an abnormal amount of methemoglobin in the blood, reducing its oxygen-carrying capacity. Methylene blue helps convert methemoglobin back to its normal form, restoring oxygen delivery to tissues.