Notice that this occurred when he was old and his heart had almost stopped following the Lord. He did go after the Lord, but he did it in a haphazard way. Solomon is perhaps the most vivid example of a Laodicean in the entirety of the Bible (Revelation 3:14-22).
His downfall began with laxity toward being careful about keeping God's commands regarding idolatry. Laxity is the first stage of lawlessness. The more lax he became, the more double-minded he became. A double minded person loses his grip. It is like trying to grasp two different objects in one's hands. If one is not really sure which he wants to hang onto, and his mind is playing back and forth between them, his grip will loosen on one or the other, because he will want to let go of the one in order to secure the other, if he feels he has a better chance with the other.
In Solomon's case, it is his mental, spiritual grip that is suspect. He gradually came to the place where he was not really hanging onto anything but straddling between choices. This made him become increasingly unstable, unsettled, and even deceitful until he became completely reintegrated into the world. He began to be moved almost entirely by human nature once again.
Why is the first commandment listed first? It is the most important of all the commandments. God wants to draw special attention to it because it is the one that is also most easily broken.