A criminal defense lawyer will protect your rights, and they will try to convince the jury that you're innocent. They'll refute what the prosecutor says by providing solid evidence and using defense strategies to show that you were either wrongly accused or meant no harm by your statements.
Still, your freedom isn't guaranteed, but an experienced attorney can help you reduce your sentence.