How to stay focused on school work when stressed and distracted?

It’s so hard to stay focused to the point where I don’t do my work and I start failing and get stressed. I get so frustrated and upset when I’m failing but it’s hard for me to prevent myself from failing. How do I keep up good pace ?