Yes. You can use the funds from your HSA to pay for certain Medicare premiums. Specifically, you can use HSA funds to pay for premiums for Medicare Part B, Part D, and Medicare Advantage plans. However, once you enroll in Medicare, you can no longer make contributions to your HSA.
You cannot use HSA funds to pay for Medigap premiums, which are private supplemental insurance policies that help cover costs not paid by Original Medicare.
While you cannot contribute to an HSA after enrolling in Medicare, you can still withdraw money from the account for non-qualified medical expenses without penalty after age 65, though you will still owe income tax on those withdrawals.