I think the closest expression with the same meaning and very similar connotations would be the French expression: C'est la vie.
meaning That's life.
You can use the French phrase as is because it is famous enough to be understood in any English speaking country.
Certainly there are some more possibilities to say it in a polite way as to avoid vulgarity: Stuff happens.
or you can use the English idiom : Worse things happen at sea. as a way of telling someone not to worry so much about their problems.
ell.stackexchange.com/users/3223/Lucian Sava
A polite and reassuring way:
"It could have been worse"
ell.stackexchange.com/users/19170/Nikhil Banerjee
Lucian's suggestion of "C'est la vie" is a good one.
There are a few other ways you could express the same idea:
Depending on the context, you might want to reference Murphy's Law.
Murphy's Law is often stated as: Anything that can go wrong, will.
This is a phrase you would use if you were talking about things going wrong before they did, or how they could have been avoided.
If you're talking about something going wrong after the fact, and especially something that could not have been prevented, you could also say: That's life!
This is a more idiomatic way of phrasing Pazzo's suggestion.
The implication is the same: in life, things happen, good and bad, and you just have to deal with it.
For a more literary tone, you could use the Burns quote suggested by TRomano's comment, the actual original phrasing of which is: The best-laid schemes
o' mice
an' men Gang aft agley
This is often misquoted in more standard English as: The best-laid plans of mice and men Oft go awry.
ell.stackexchange.com/users/5807/chapka
Things happen in life that we may not like. or Bad things happen.
ell.stackexchange.com/users/None/
To avoid the expletive, you could just say "stuff happens", which is somewhat idiomatic (though not nearly so idiomatic as "shit happens").
That's still rather informal
but, in the right context and used only occasionally, informality can work well in an essay.
It lightens the mood.
Be careful not to over-use informality and be careful that it's only a little break from the serious stuff and that it doesn't ruin the flow.
ell.stackexchange.com/users/4468/David Richerby
I am trying to write an essay and the only phrase I can think of is "shit happens". I'm wondering; is there any formal way to say  shit happens ?
Is there a polite, formal way to say "sh!t happens"?
ell.stackexchange.com
<politeness><slang>
ell.stackexchange.com/questions/55517
ell.stackexchange.com/users/19163/Jasmine Cornwell
Alternative suggestions include "it could have been worse", "c'est la vie", "stuff happens" or your could even refer to Murphy's Law, depending on the context. Stuff happens, c'est la vie, it could have been worse and Murphy's Law are all things you could say.
Stuff happens, c'est la vie, it could have been worse and Murphy's Law are all things you could say.