Britney Spears reveals a personal experience she has kept private for two decades in her upcoming memoir.

During her relationship with Justin Timberlake, Spears became pregnant by the singer and had an abortion, she writes in a book excerpt published by .

鈥淚t was a surprise, but for me, it wasn鈥檛 a tragedy. I loved Justin so much. I always expected us to have a family together one day. This would just be much earlier than I鈥檇 anticipated,鈥 Spears writes in her book, 鈥淭he Woman in Me.鈥

鈥淏ut,鈥 she writes, 鈥淛ustin definitely wasn鈥檛 happy about the pregnancy. He said we weren鈥檛 ready to have a baby in our lives, that we were way too young.鈥

CNN has not yet been able to independently review 鈥淭he Woman in Me.鈥

A representative for Timberlake did not respond to CNN鈥檚 request for comment.

In the excerpt, Spears writes about how she felt conflicted at the time

鈥淚f it had been left up to me alone, I never would have done it,鈥 she writes. 鈥淎nd yet Justin was so sure that he didn鈥檛 want to be a father.鈥

鈥淭o this day, it鈥檚 one of the most agonizing things I have ever experienced in my life,鈥 she adds.

Timberlake and Spears dated from 1999 until 2002.

Spears later married dancer Kevin Federline and had two sons, Sean Preston, 18, and Jayden James, 17, prior to her and Federline divorcing in 2007.

Timberlake married actress Jessica Biel in 2012 and the pair are the parents of two young sons, Silas and Phineas.

鈥淭he Woman in Me鈥 publishes on Oct. 24.