Temporal complexity – Why was it thought that the test of primality was NP?

To check if $ n $ is first, just try to divide $ n $ in number up to $ sqrt {n} $, which means that the complexity would be $ O ( sqrt {n}) $. In my opinion, $ O ( sqrt {n}) <O (n) $ so this simple algorithm is already P. But why did people think that the primality test is NP and were surprised by the AKS primality test?