Introduction: Lesbian, gay, bisexual and transgender people still face discrimination in healthcare environments and physicians often report lack of knowledge on this population's specific healthcare needs. In fact, recommendations have been put forward to include lesbian, gay, bisexual and transgender health in medical curricula. This study aimed to explore factors associated with medical students' knowledge and attitudes towards homosexuality in different years of the medical course. Material and Methods: An anonymous online-based questionnaire was sent to all medical students enrolled at the Faculty of Medicine -University of Porto, Portugal, in December 2015. The questionnaire included socio-demographic questions, the Multidimensional Scale of Attitudes Toward Lesbians and Gay Men (27 items) and a Homosexuality Knowledge Questionnaire (17 items). Descriptive statistics, ANOVAs, Chi-square tests and Pearson's correlations were used in the analysis. Results: A total of 489 completed responses was analyzed. Male gender, religiosity and absence of lesbian, gay or bisexual friends were associated with more negative attitudes towards homosexuality. Attitudinal scores did not correlate with advanced years in medical course or contact with lesbian, gay or bisexual patients. Students aiming to pursue technique-oriented specialties presented higher scores in the ` Modern Heterosexism' subscale than students seeking patient-oriented specialties. Although advanced years in medical course correlated significantly with higher knowledge scores, items related with lesbian, gay or bisexual health showed the lowest percentage of correct answers. Conclusion: There seems to be a lack of exploration of medical students' personal attitudes towards lesbians and gay men, and also a lack of knowledge on lesbian, gay or bisexual specific healthcare needs. This study highlights the importance of inclusive undergraduate curriculum development in order to foster quality healthcare.