Condom came off in me

The other night my boyfriend and I were having sex when the condom came off. We looked all over for it before realizing it had to be inside me. No big deal I google some things and we got it out within 10 minutes. I'm wondering what might have caused the condom to come off and what we can do to prevent it? It was our first time and I don't want it to happen again lol