How does a Bitcoin block get generated and 'agreed upon' by everyone? When a set of new transactions is broadcast to all the Bitcoin mining pools, my understanding is that they all start working on a new block to include all those transactions.  But how is it agreed upon which block is the next one to be included in the Bitcoin blockchain?  Is it just the first mining pool to generate the block?  And if that's the case, isn't it going to be tremendously wasteful if all but one mining pool have been working on generating a new block but all that work is wasted because their block wasn't chosen to be the next one in the chain?
Miner ASICs have one job: Change the meaningless parts of the block until the difficulty target (related to the hash of the block) is satisfied.
ASICs connect to the pool to first download the block template (they regularly do that - maybe every few seconds?). The block template contains the transactions. They calculate the merkle hash of the transactions, embed it in the block header, and hash the block header many times.
When the target is satisfied, the block is published. From then on, no one can change the transactions in the block.

all that work is wasted

This is a lottery where everyone's chances of finding the next block is proportional to their hashrates. If you need to mine all day to find one block per day -- congratulations! You can afford solo mining and you don't lose anything, and your reward is fair.
Trivia: Block mining is a Poisson process. One property of this is memory-less-ness. That is, given that the average time until the next block is 10 minutes (it is for Bitcoin):

After about how many blocks will someone find a block if everyone started just now: 10 minutes (t = 10)
What if you all had been mining for 2 minutes? Still 10 minutes (block to be released at t = 12)
What if you all had been mining for 20 minutes? Still 10 minutes (block to be released at t = 30)

Here's a fun puzzle by Russel O'Connor and Pieter Wuille.
So, there is no wasting in mining: it's memoryless. If you fail, you just keep trying, and everything works as intended in the end.