One of the main jobs of a criminal defense attorney is to carefully collect and analyze all of the evidence in the case to see if there are issues that can get the case thrown out, or ways that you can potentially win the case at a jury trial. If, after all of that review, you find that you probably can’t just get rid of the case, then it is important to negotiate with the other side to mitigate the damage that this case is going to cause your client.
A lot of that depends on the client’s situation. Is their main concern keeping their record clean? Is their main concern not facing any jail or prison time? Prosecutors are willing to give your client something in order that they don’t have to waste the state’s time and resources litigating the case, so you negotiate with them to get something favorable for your client, save the client from having to go to trial and face whatever punishment comes afterwards.