The economy is strong and stocks are near record levels. But a long-running survey shows retirees’ confidence in having enough money to cover basic living expenses has dropped over the past year, due in part to concerns about medical expenses.

Released Tuesday by the nonprofit Employee Benefit Research Institute, the survey shows that 80% of polled retirees are optimistic about their ability to afford basic expenses, down from 85% last year.

Driving...