From the moment 17-year-old Donald Trump was named a captain for his senior year at New York Military Academy, he ordered the officers under his command to keep strict discipline. Shoes had to be shined. Beds had to be made. Underclassmen had to spring to attention.

Then, a month into Trump’s tenure in the fall of 1963, came an abrupt change.

The tall, confident senior with a shock of blond hair was removed from that coveted post atop A Company and transferred to a new job on the school staff — another prestigious assignment, but one with no command responsibilities. He moved out of the barracks and into the administration building, swapping jobs with a fellow high-ranking senior who took command of Trump’s old group.

Explanations vary as to what actually happened.

In Trump’s telling, he was elevated as a reward for stellar performance. “I had total control over the cadets,” he said in a recent interview. “That’s why I got a promotion — because I did so good.”

Donald Trump, on the “popularity poll” page of the1964 New York Military Academy yearbook. The caption below his photo reads “Ladies' man: Trump.” (Courtesy of New York Military Academy)

Former cadets recall the change differently. They say school administrators transferred Trump after a freshman named Lee Ains complained of being hazed by a sergeant under Trump’s command. School officials, those cadets say, were concerned that Trump’s style of delegating leadership responsibilities while spending a lot of time in his room, away from his team, allowed problems to fester.

“They felt he wasn’t paying attention to his other officers as closely as he should have,” said Ains, who lives in Connecticut and works in the aerospace industry.

Bill Specht, the cadet who switched places with Trump, recalled an administrator telling him about the hazing incident and saying that “the school has decided that they are going to make a switch.”

The incident, previously unreported, offered an early glimpse into a pattern that would follow Trump through much of his life and has been evident in his rise as a leading Republican presidential candidate. Often the center of controversy, he finds a way to emerge by declaring victory and claiming success, even if the facts are more complicated and some people around him are left with sour feelings.

The commandant who ordered the transfer, Col. Joseph C. Angello, has since died. School officials declined to comment.

Trump often points to his five years at the academy in Cornwall-on-Hudson, about 60 miles from his home town of New York City, as a formative period in his life that helps qualify him to be commander in chief.

Although he received educational and medical deferments from the Vietnam War draft, he has said that the school provided him “more training militarily than a lot of the guys that go into the military.”

Donald John Trump, pictured in his 1964 New York Military Academy yearbook. (Courtesy of New York Military Academy)

“I did very well under the military system,” Trump said in an interview. “I became one of the top guys at the whole school.”

Interviews with cadets who knew him well and a close mentor reveal a more complex picture of Trump’s experience at the school. As a maturing teenager, he began to exhibit some of the traits the world would come to know through his fame as a real estate mogul, reality TV star and White House contender. Even at an academy renowned for imposing strict standards on its cadets, Trump often managed to play by his own rules. He often left campus on weekends and drew the envy of fellow students for his habit of bringing attractive women to the school. He also stirred resentment from some in his orbit.

A half-century later, discussing that time triggers discomfort and some bitterness among Trump’s former classmates.

Ains, for instance, spoke of the episode reluctantly, after months of not returning phone calls, and only through a cracked door when a reporter appeared at his Connecticut home.

Trump, 69, vigorously rejected the accounts of his former classmates’ recollections, lashing out at The Washington Post over the course of three phone interviews for “doing a lousy story.” He attacked his former fellow cadets, calling Ains’s account “fiction” and accusing him of speaking only “to get himself a little bit of publicity.” Regarding Specht, the cadet who replaced him in A Company, Trump said the transfer “was a promotion for me, and it was a demotion for him.”

After an initial interview, Trump called The Post twice to argue his point.

“I was promoted. The word is ‘promoted’ — Mark it down,” Trump said.

‘I liked to test people’

Trump’s military school education began in 1959.

He was a 13-year-old with a history of trouble at school, and his father, Fred Trump, a prominent New York real estate developer, sent him to the academy to be straightened out.

“As an adolescent, I was mostly interested in creating mischief,” Donald Trump wrote in “The Art of the Deal.”

“I liked to stir things up, and I liked to test people.”

New York Military Academy was founded in 1889 by Civil War veteran Charles Jefferson Wright. The school boasted of its record whipping rebellious youths into shape. “Courageous and gallant men have passed through these portals,” reads an inscription over the front door where frustrated parents dropped off their defiant sons.

The school was as conservative in both its content and culture. Students were not allowed off campus during the week. On top of such courses as math and English, students tackled military history and learned how to fire rifles and mortars. Girls would not be allowed to attend until more than a decade later.

Theodore Dobias, a World War II veteran and Army colonel who was a training officer at the school, said in an interview that he recalled the young cadet needing time to acclimate to the rigors of academy life.

“At the beginning, he didn’t like the idea of being told what to do, like, ‘Make your bed, shine your shoes, brush your teeth, clean the sink, do your homework’ — all that stuff,” said Dobias, who became a mentor to Trump.

Before Trump’s ascent to the rank of captain during the summer preceding his senior year, Trump was promoted steadily but unremarkably his first four years. During that time, he rose to the rank of supply sergeant while some fellow juniors were already lieutenants. He was quieter and humbler than he is now, some classmates said, and did not brag about his family’s wealth.

“I remember having a conversation with him where he said his dad was a builder, and I said, ‘My dad was a builder, too,’ ” said Jeffrey Pollack, who was in A Company. It wasn’t until several years later that Pollack picked up a news magazine, read about the Trump family fortune and realized what his classmate had meant.

But even within the confines of a military school, there were hints of the brash and boastful persona now known as “The Donald.” Playing baseball, he stood out as a great first baseman, Dobias said.

“Even then, he wanted to be number one,” Dobias said. “He wanted to be noticed. He wanted to be recognized. And he liked compliments.”

Thanks to his athletic prowess, Dobias said, Trump was a “big shot” on campus. “And you get that by working hard, and he did work hard,” Dobias said.

Fellow cadets recalled discussing how Trump carried himself as if he were destined for success, even if they were never sure if it was because of his charisma, his rank, his family’s wealth or some other reason.

“There was some air about him,” recalled Michael Pitkow, “as if he knew he was just there passing time until he went on to something greater.

“He was self-confident and very soft-spoken, believe it or not, at the time,” added Pitkow, who said he overlapped with Trump for one year at the academy. He also noted that Trump, when he commanded A Company, seemed friendlier than other high-ranking students. “Occasionally, he inspected my company. He might have said something like, ‘Your shoes look good.’ He was usually pretty positive, unlike other commanders, who could be very driven by their egos and the power they commanded.”

Philip Beckerman, who played varsity soccer with Trump, remembered his teammate as a “decent guy” with a lot of friends.

“I always liked him,” Beckerman said. “He was very different than he projects himself today. He was down to earth.”

‘Definitely privileged’

Some former classmates said Trump seemed to enjoy luxuries others did not. His higher rank during his senior year allowed him to leave campus on weekends and holidays when other students remained at the school. Trump and several friends went on a chaperoned school trip to Bermuda, some former cadets said.

Trump never received favorable treatment, Dobias and the candidate said. Yet some lower-ranking cadets wondered whether Trump’s wealth played a role.

“He was definitely privileged,” said Douglas Reichel, who said he was a year behind Trump and a member of A Company. “That group of people got treated much differently. They got promoted each year.”

Trump often brought young women to the school — although they weren’t allowed as far as his room — earning him the title of “Ladies’ Man” in his senior yearbook.

“They were beautiful, gorgeous women, dressed out of Saks Fifth Avenue,” remembers George White, a former cadet who at the time spelled his last name Witek.

Trump describes his time at the academy as a crucible in which he proved himself and learned to lead.

“I think I was treated very much like everyone else,” he told The Post. “They had a lot of drill sergeants there. Literally, drill sergeants. And they were tough, and it was less politically correct than it is today. They were really rough cookies. You had to learn how to survive, essentially, with some of these guys. I learned discipline — how to dish it out and otherwise.”

Trump’s appointment prior to his senior year as captain, presiding over NYMA’s most prestigious company, surprised some of his fellow cadets, particularly a handful who were ranked higher than him as juniors but suddenly found themselves behind him as seniors.

“He was really an afterthought,” White said. “He didn’t show much as a freshman, sophomore or even a junior, because he would have already been more than a supply sergeant.”

During his short stint as head of A Company, Trump had a hands-off approach to his position, according to five former cadets interviewed by The Post. He would usually head straight from dinner to his room, leaving his officers to inspect the cadets.

In his absence, he would order his officers to keep younger cadets in line, and the atmosphere within A Company quickly became tense. Hazing was an integral part of school culture, and without the firm hand of A Company’s commander, underclassmen felt at risk, cadets said.

“He was a delegator,” said Ains, the former cadet who said he was hazed. “I think he knew a lot of things [going on in the barracks], but I don’t know how far he dug into it.”

Ains took the rare step of complaining to school administrators about the alleged hazing incident, in which he said a sergeant threw him against a wall. The sergeant was demoted, Ains remembers, and Trump was moved from A Company to the school staff.

White, who as battalion commander was NYMA’s top-ranking cadet and the top member of the staff that Trump was switched to, recalls being shocked when the school commandant called him into his office to announce that Trump would be taking Specht’s spot. The move took place “to get him out of the barracks,” recalled White. “What was I going to say? That was the order.”

Specht, Trump’s replacement, immediately cracked down on hazing in A Company, Ains said. “He would come around to the different rooms at any time and make sure that the students were studying and that they weren’t being interfered with by any older cadets,” Ains said.

Specht said he remembers well the moment the school commandant gave him the news.

“Colonel Angello called me down and said, ‘You’re going to go to A Company, and Donald is taking your position on the staff as a captain,’ ” Specht recalled. Specht said Angello referred to a “hazing incident” in A Company as he explained that “the school has decided that they are going to make a switch.”

The sudden swap was a disappointment for Specht, who had been at or near the top of his class since arriving at NYMA.

“I obviously wasn’t happy about the switch, because it was more work for me,” he said.

Specht, who served in the Navy after graduating from NYMA and is a Trump supporter, said he didn’t want to get into a public spat with the billionaire candidate. His wife, however, took the phone from her husband during an interview to challenge Trump’s account.

“It’s a fact,” Christine Specht said. “I’m Bill’s wife, and he was not demoted.”

Trump told The Post that he never saw any hazing at the school.

“I did a good job, and that’s why I got elevated,” he said. “You don’t get elevated if you partake in hazing.”

Trump, who in 2012 offered $5 million for the release of President Obama’s college transcript and other documents, said he would not give The Post permission to review his records from the military academy.

“I’m not letting you look at anything,” he said. “Why would I let you look at my records? You’re doing a lousy story.”

Dobias, Trump’s mentor, said he had no knowledge of the hazing incident that allegedly took place during Trump’s command. Dobias said he recalled that Trump’s replacement had been brought into A Company to keep a closer watch on cadets.

Moving Trump “was the choice of the commandant, and there must have been a good reason for it,” Dobias said. “I think the guy who took over A Company was a little tougher on the kids than Donald was, so they moved [Trump] up onto the staff.”

When told during a phone interview last month of Dobias’s comments, Trump called The Post back an hour later with the 89-year-old retired instructor on the line.

“Dobie, let me ask you this,” Trump said, using his mentor’s nickname. “Did I have total control over everybody when I ran the company?”

“Yes, you did,” Dobias answered.

For 20 minutes, Trump pressed his former instructor to back up his account of receiving a “major promotion.”

“Would you tell him officially that the word is ‘promoted’?” Trump told Dobias.

When asked directly about Dobias’s comment that Trump had been switched out of A Company because he wasn’t tough enough on the cadets, Trump shot back: “I guarantee he didn’t say that.”

A moment later, Dobias seemed to strike a middle ground: “Donald Trump wasn’t tough enough on the kids, so he got promoted on the staff.”

Whatever the reason for Trump’s transfer, it ultimately served as a de facto promotion. It was Trump, not Specht, who chaperoned visiting dignitaries around the academy during their senior year. And it was Trump, not Specht, who, just a few days after the transfer, was put in charge of a special drill team for New York City’s Columbus Day parade.

White, the school’s top cadet, recalled being told by the commandant to let Trump lead the school during the event.

“He was singled out as early as October for special treatment,” said White. “They were keeping Trump busy and out of mischief.”

On Oct. 12, a white-gloved Trump led not only NYMA but the entire parade down Fifth Avenue to St. Patrick’s Cathedral, where he was met by Cardinal Francis Spellman.

For Trump, the photos of that day are proof enough that his time at NYMA was nothing but successful.

“I was always good at that school,” he said. “Take a look at the pictures. I’m standing at the head of the whole place.”

Alice Crites contributed to this report.