On screen: Failed to login: Invalid session (Try restarting your game)
This one genuinely goes both ways, so the first job is telling which you are looking at.
When you join an online-mode server, your client posts to sessionserver.mojang.com to join, and the server then calls hasJoined to confirm it. If your access token has expired or been revoked, or the session service returns anything other than success, the server rejects you with this message.
The usual causes: the game sat open for hours and the token expired; the same Microsoft account signed in somewhere else and invalidated the token; two copies of the game are running; Microsoft or Mojang authentication is degraded or rate-limiting; the server runs online-mode=true and the client is not properly authenticated; or a stale refresh token in Prism or MultiMC.
Worth knowing: since the move to Microsoft accounts, Minecraft Java authenticates through Xbox Live. An Xbox Live sign-in outage takes Minecraft Java down with it, which is a connection almost no guide mentions.
If singleplayer and offline-mode servers work but no online server will let you in, it is the token or the auth service. If everyone on a server was kicked at the same moment and Xbox Live sign-in is having problems, it is Microsoft's side. If it is only you and restarting the launcher fixes it, it was your local token.
Neither Mojang nor Microsoft publishes an article for this exact string. The mechanism above comes from the documented join and hasJoined protocol flow rather than from a support page, and we would rather say so than attribute an explanation to Mojang that they never wrote.
When you join an online-mode server, your client posts to sessionserver.mojang.com to join, and the server then calls hasJoined to confirm it. If your access token has expired or been revoked, or the session service returns anything other than success, the server rejects you with this message.
This one genuinely goes both ways, so the first job is telling which you are looking at.
Start with: Close the game and the launcher completely, then reopen. This refreshes the token, which is literally what the error message is asking for. Closing only the game is not enough.