How can you fix a toilet that groans at the end of the flush?

Replace the fill valve (ballcock). The type that uses a diaphragm, like fluidmaster, will shut it off quicker. Reason that occures: vibrations in the pipe from the fill valve when the water flows through the ballcock ( like a whistle does with air), but water makes a deeper sound and sometimes vibrates quite loudly once that starts. If that doesn't fix it, try replacing the supply water valve.