How can I make combat challenging, without simply making it take longer?

My players and I like to have fewer, harder combat encounters, as we’d rather be roleplaying than working through combats that we know the PCs will win.

It seems hard to arrange for this in 5e. I calculate the XP thresholds for my three PCs, and build a hard encounter, and either (a) they are wiped; or (b) they win, but it takes ages and ages because enemy HP is so high.

How can I build hard but winnable encounters which don’t drag due to very high monster HP values?