There are a lot of articles and books says that magic is nothing but a science that is not defined yet or in simple words, magic is the science we are not aware of.
But a greater version of magic is miracle. Now a miracle is something which is totally unpredictable. But it has its valid reasons.
To understand the relation, there are 3 dimensions of perception:
1. Cause and effect dimension: In this, a person is rather to know the result of a cause and that can be obtain with mistaken experiments that lead to no conclusion. Thus the person concludes its magic.
2. Chaotic Dimension: In this, a person is totally unaware of cause as well as effect. The person can only witness the action. And when analyzed after some time the reason behind the chaos is sometimes obtained certain.
3. Prayer and Solution dimension: when the person really thinks that there must be some sort of solution or way to come out of chaos then it really happens that you feel blank and totally unware of actions that helped you from chaos. The person can never define it's cause and calls this a miracle.
Point 1 is sometimes magic. Point 2 is almost magic and point 3 is totally miracle where you find the connection to the one God.