"I invented a history for her that incorporated real people and events, including some of my other ancestors.
"I created a friendship between my heroine and Princess Louise, Queen Victoria's sixth child, and I drew on many parallels from my life for Lady Margaret's journey.
"I have long held a passion for historical research and telling the stories of strong women in history through film and television. I am proud to bring my personal brand of historical fiction to the publishing world."
The duchess' ex-husband, and their children, Princesses Beatrice and Eugenie, have not yet read the manuscript.
Sarah's spokesperson said: "She wants it to be a surprise."
Sarah has previously written many books for children but Her Heart for a Compass is her first adult novel and was written with the help of "collaborator and mentor" Marguerite Kaye, who has written more than 50 historical romances for Mills & Boon.
The duchess enjoyed the experience so much, she is already working on her second.
Lisa Milton, an executive publisher for Mills & Boon, said: "This brilliant sweeping story is perfect for our existing readers as well as reaching fans of bestselling novelists such as Philippa Gregory and Anne O'Brien.
"Mills & Boon are honoured to publish the Duchess of York's debut novel as we move into our next century of publishing brilliant books by women for women."