It’s hard to say these days because the lines between producer, engineer, and songwriter have blurred quite a bit in the past decade with the advent of cheap digital music production tools. A guy writing music in his bedroom on his laptop is just as much a producer as Rick Rubin in a state of the art studio. But, here’s my take on it since I’ve worn all 3 hats at one time or another.
I would say a producer is someone who runs the recording sessions and keeps them moving smoothly as well as gives input regarding musical direction, radio-friendliness, etc. Does the band need a session musician for a string part? The producer schedules it. Is a song structure just not working? The producer says “move this chorus here” or “take out that last verse”. Is the singer having trouble getting a take just right? The producer calls for a break and dials up the hookers and blow to loosen him up.
The engineer is more the technical guy. He knows exaclty what mic, amp, compressor, etc. to use to get the sounds that the producer and artist want. He’s running the board, patching cables, and keeping gear in tiptop shape.
In genres like Pop, Hip Hop and R&B - a producer will frequently get songwriting and engineering credits because they’re usually responsilble for a large part of the musical bed that talent is singing or rapping over. Most electronica is like this as well, where in fact one person could do the whole shebang by his or herself.