O'Brien did not graduate the acadamy. He was a non-commissioned officer, or 'enlisted,' referring to Starfleet officers who did not graduate the academy and typically have a very specialized skill. They sign up for certain posts, and receive basic training and a few courses specific to their post and skill, and then they are on the job, without the 4 years of academy training.
Non-commissioned officers are outranked by any and all commissioned officers, including ensigns. This can be different in certain circumstances, such as when he becomes Chief of Operations on Deep Space Nine. Due to his important position there, he is allowed to give orders to commissioned officers that are part of his engineering team. You cannot be demoted from an officer rank to an enlisted rank unless you've been stripped of your commision as punishment, an exceptionally morfe harsh than a step down in rank.
In the original novelisation of The Emissary, OBrien was given a comission and promoted to ensign to assume his position but this was never stated on screen.
There was not any canonic mention of O'Brien graduating from the academy, however, there was one in-screen reference to him having attended a class at the academy - Temporal Mechanics - but advanced classes can be attended by non-enlisted personnel as well, so this is not as much a discrepancy as it is a reference that wasn't fully explainined.