you can try to get a custody of a child (Sorgerecht) through the court procedure, if the mother rejects to give it to you. The chance is open, it depends on the situation: if you are really caring for a child or are prepared and able to do it, how is your relation to the mother etc. Anyway you can first speak to Jugendamt, like Meike wrote, and try to convince them on your good intentions.
Your chance to stay in Germany can be better with the custody of child, but only if you really care for the child and it can be proved. If it is a German child, your chance is better. But there is no general guarantee that you can't be deported. Even with a parent of a German child it can be the case. It depends on your personal situation and on the Ausländerbehörde.
If you really care for the child and have a document that you are the father, you have some chance to get a residence permit even without Sorgerecht. The more important question is, if you can really care for the child intensively. Why does the mother rejects giving you Sorgerecht? If you don't live together and you don't see the child regularly, your chance is mostly lower.
This is naturally a very general opinion. You must better consult a lawyer who has expertise both in migration law (nesessarily) and family law. Or you must find a good councelling center, which can analyse your situation on an individual basis in detail.