Yes and no!
It is a bit tricky explaining how they sleep because it does not occur how we traditionally think it does. A big difference between the way we sleep and how they do it, is the fact that we are capable of completely shutting down our brains. Humans are involuntary breathers, meaning we can sleep on our own even while entirely unconscious! Whales are not capable of doing so.
To be able to fully rest, whales shut down half of their brain at a time. They need to be partially awake in order to continue breathing and be aware of their surroundings. This makes them voluntary breathers. Usually, the whale will stay in place as they sleep at or near the surface, or move at a gentle pace. As they are resting, they are switching which side of their brain is awake. Depending on if it is the right or left side that is asleep, sometimes the opposite eye will be shut. This concept is known as unihemispheric sleep.
There are many dangers they can face when remaining at the surface for a long period of time. When whales are sleeping, it is referred to as logging. This is because the body of the whale resembles a log on the surface of the water and can easily blend in. This makes it difficult for those on vessels to spot them and can result in dangerous collisions for both whales and the humans. As such, it is important for vessels that travel in areas known to contain whales to travel at safe speeds where they can give themselves time to scan the water around them for sleepy whales!