Importance: Vitamin D treatment has been found to decrease the incidence of viral respiratory tract infection, especially in patients with vitamin D deficiency. Whether vitamin D is associated with coronavirus disease 2019 (COVID-19) incidence is unknown. Objective: To examine whether the last vitamin D status before COVID-19 testing is associated with COVID-19 test results. Design, Setting, and Participants: This retrospective cohort study at an urban academic medical center included patients with a 25-hydroxycholecalciferol or 1,25-dihydroxycholecalciferol level measured within 1 year before being tested for COVID-19 from March 3 to April 10, 2020. Exposures: Vitamin D deficiency was defined by the last measurement of 25-hydroxycholecalciferol less than 20 ng/mL or 1,25-dihydroxycholecalciferol less than 18 pg/mL before COVID-19 testing. Treatment changes were defined by changes in vitamin D type and dose between the date of the last vitamin D level measurement and the date of COVID-19 testing. Vitamin D deficiency and treatment changes were combined to categorize the most recent vitamin D status before COVID-19 testing as likely deficient (last level deficient and treatment not increased), likely sufficient (last level not deficient and treatment not decreased), and 2 groups with uncertain deficiency (last level deficient and treatment increased, and last level not deficient and treatment decreased). Main Outcomes and Measures: The outcome was a positive COVID-19 polymerase chain reaction test result. Multivariable analysis tested whether vitamin D status before COVID-19 testing was associated with testing positive for COVID-19, controlling for demographic and comorbidity indicators. Results: A total of 489 patients (mean [SD] age, 49.2 [18.4] years; 366 [75%] women; and 331 [68%] race other than White) had a vitamin D level measured in the year before COVID-19 testing. Vitamin D status before COVID-19 testing was categorized as likely deficient for 124 participants (25%), likely sufficient for 287 (59%), and uncertain for 78 (16%). Overall, 71 participants (15%) tested positive for COVID-19. In multivariate analysis, testing positive for COVID-19 was associated with increasing age up to age 50 years (relative risk, 1.06; 95% CI, 1.01-1.09; P = .02); non-White race (relative risk, 2.54; 95% CI, 1.26-5.12; P = .009), and likely deficient vitamin D status (relative risk, 1.77; 95% CI, 1.12-2.81; P = .02) compared with likely sufficient vitamin D status. Predicted COVID-19 rates in the deficient group were 21.6% (95% CI, 14.0%-29.2%) vs 12.2%(95% CI, 8.9%-15.4%) in the sufficient group. Conclusions and Relevance: In this single-center, retrospective cohort study, likely deficient vitamin D status was associated with increased COVID-19 risk, a finding that suggests that randomized trials may be needed to determine whether vitamin D affects COVID-19 risk.