All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
It is obligatory on you to perform Ghusl (ritual bath) for Janaabah (state of major ritual impurity) because you felt that the semen has moved from its original place and it then came out afterward. According to the Kuwaiti Fiqh Encyclopedia: “A person is considered in a state of Janaabah if he felt that his semen has moved from its original place with lust and it then came out without lust. This is the view held by the Maaliki, Shaafi‘i, and Hanbali scholars as well as Abu Haneefah and Muhammad, contrary to the opinion of Abu Yoosuf in this regard. According to Abu Yoosuf, the criterion is the departure of semen from its original place along with its coming out with lust.” [End of quote]
Also, your fasting is invalidated if you intentionally ejected semen. Ibn Qudaamah said in Al-Mughni: “If one masturbates with his hand, he has committed a prohibited act; his fasting is not invalidated by it unless he discharges (semen). If he discharges (semen), his fasting is invalidated because it is similar to the kiss in terms of arousing sexual desire.” [End of quote]
Allah Knows best.