What does a defense attorney do in a court case?

The defense attorney tries to get the defendant not guilty. The prosecutor is the opposite.

They also plead for a lighter sentence from the judge.