Miners repeatedly hash block data until they find a result below a target. Finding it is hard; checking it is instant. The winner gets the block reward and fees.
Attacking a PoW chain would require more computing power than all honest miners together, which is why Bitcoin's growing hash rate is read as rising security.