"One of the most dangerous in the world".
But yes, it's also true that the US has backed Pakistan, sold them F-16s etc. This is the problem: the US can back countries that it itself regards as dangerous!
Pakistan was definitely a problem in the War on Afghanistan. The northwestern area of Pakistan, the "federally administered tribal areas", are basically lawless and Taliban could operate from there and strike over the border. There were also attacks on US convoys.
Invading Afghanistan without having either a coastline or a neighbouring solid ally was a big part of the disaster. Every air conditioner running on a US base was powered by diesel that had to be trucked two thousand miles across semi-hostile territory.
On one hand, as you say, they're an "ally" with US bases etc. On the other they actively assisted the Taliban. They've been useful in some situations, but have undermined the US in others. It's not clear whether they'd side with the US or China. And they leak nuclear secrets like a sieve. Plus they're basically turning into an Islamic theocracy so the long term does not bode well for the US.