Background: The literature investigating female and male medical students' differing career intentions is extensive. However, medical school experiences and their implications for professional identity formation and specialty choice have attracted less attention. In this study we explore the impact of medical school experiences on students' specialty preferences, investigate gender similarities and differences, and discuss how both might be related to gender segregation in specialty preference. Methods: In a questionnaire, 250 Swedish final-year medical students described experiences that made them interested and uninterested in a specialty. Utilizing a sequential mixed methods design, their responses were analyzed qualitatively to create categories that were compared quantitatively. Results: Similar proportions of women and men became interested in a specialty based on its knowledge area, patient characteristics, and potential for work-life balance. These aspects, however, often became secondary to whether they felt included or excluded in clinical settings. More women than men had been deterred by specialties with excluding, hostile, or sexist workplace climates (W = 44%, M = 16%). In contrast, more men had been discouraged by specialties' knowledge areas (W = 27%, M = 47%). Conclusions: Male and female undergraduates have similar incentives and concerns regarding their career. However, the prevalence of hostility and sexism in the learning environment discourages especially women from some specialties. To reduce gender segregation in specialty choice, energy should be directed towards counteracting hostile workplace climates that explain apparent stereotypical assumptions about career preferences of men and women.