The fluid coming out is probably the amniotic fluid
which surrounds the baby. This bag of water surrounding the baby bursts spontaneously releasing hormones which induce labor.
This explains the reason of your pain.
If the consistency of the fluid is like water/ urine that is a thin fluid it is probably that your bag of water is leaking.
If the discharge is thick mucoid then also you need consultation as this also indicates progress to labor.
Also if the fluid is watery with greenish hue, you should not delay consultation as it could be an indication of baby being not well inside.
Do visit your gynecologist at the earliest. You require internal examination.