This is all dependant on you having "Save history when conversations are closed" checked in Messages prefs - otherwise you can find the conversation, but not rejoin it to your main chat window.
The procedure is different if "Messages in Cloud" is enabled, which unchecks & disables the "Save History…" pref.
Both versions below [edited heavily over time].
I have retested this Jun 2022, with "Messages in Cloud" enabled…
Switch your phone off.
Log out of Messages on the Mac then quit the app
Navigate to ~/Library/Messages/
Enter Time Machine & navigate back in time until before your error.
Select the chat.db file & restore
[alternatively grab this file from any other backup, Backblaze etc.]
Reboot, open Messages & check messages are restored.
Boot the phone
If you're lucky, you should be back to sanity.
Without "Messages in Cloud enabled…
You cannot directly re-open the last conversation you had from the app itself, if you already closed it by hitting the x.
You need to dig in history, it's located at ~/Library/Containers/com.apple.ichat/Data/Library/Messages
Conversations are stored by date. You only need to find any one instance of the conversation you are looking for.
Double-clicking that file will reopen it in a separate window in Messages.
Keep that window open, or the next step fails.
To persuade it to reattach to the main window…
Scroll down your conversations list - it will have reappeared in last place.
Select it, it will appear to be empty, but will fill as soon as you click it.
You can now close the extra window.