There are already a few questions that ask how to ensure a minimal length for the last line of a paragraph: Ensure minimal length of last line and Minimum length of last line of a paragraph. But unless I'm mistaken, both the accepted answers work by lengthening the final line until it is acceptably long. Is there a way of doing the opposite—reducing the spaces between words on the second-to-last line until the material on the last line can fit at the end?
The use case for this is to deal with short words and bits of math that end up on their own on the last line of a paragraph.
I imagine there would only be one parameter for the user to set: the maximum amount that the space between words on the second-to-last line can be reduced.
LuaLaTeX solutions are perfectly welcome.