A miscarriage, in medical terms, is the birth of a fetus before it's able to live independently of its mother. In other words, a miscarriage is the abrupt, early end of a pregnancy.
The medical sense of miscarriage, which usually describes the very early loss of a pregnancy (later losses are often called stillbirths), is actually among the newer uses of the word. In the sixteenth century, a miscarriage was almost always a "mistake or error" or sometimes "misbehavior." Today, when something doesn't go the way it was supposed to, you might call it a miscarriage.