COLLEGE STATION, Tex. — “An Aggie does not lie, cheat or steal, or tolerate those who do.”

For each of Texas A&M’s 64,000 students, otherwise known as Aggies, those words are intended as a creed. The Aggie Code of Honor is drilled into freshmen at a required orientation session. It appears at the end of all written exams, followed by a space for students to sign their assent. A marble monument to the code graces the university’s 5,200-acre campus in College Station, approximately midway between Austin and Houston.

Violating the code is serious business. But that is what Rick Perry — the United States energy secretary, former Texas governor, two-time presidential candidate and A&M alumnus (class of 1972) — has accused the university’s Student Government Association of doing.

In an op-ed published in The Houston Chronicle on Wednesday, Mr. Perry claimed the S.G.A. had rigged the election for student body president to favor an openly gay candidate, Bobby Brooks.

Mr. Brooks finished second in the balloting, which was held Feb. 23-24. But the winner, Robert McIntosh, was disqualified because he failed to properly document a campaign expense: glow sticks that appeared in a campaign video.

“Brooks’ presidency is being treated as a victory for ‘diversity,’” Mr. Perry wrote in the Chronicle. “It is difficult to escape the perception that this quest for ‘diversity’ is the real reason the election outcome was overturned. Does the principle of ‘diversity’ override and supersede all other values of our Aggie Honor Code?”

Cabinet secretaries do not customarily weigh in on student government elections. But Mr. Perry is no ordinary cabinet secretary, and Texas A&M is no ordinary university.

Being an Aggie is central to Mr. Perry’s identity.

As an undergraduate at A&M studying animal science, he was twice elected Yell Leader — a prestigious position that entails leading cheers at football games. He was also in the Corps of Cadets, an R.O.T.C.-like organization whose members wear a uniform of jodhpurs, riding boots, and spurs.

Texas A&M tends to inspire fierce loyalty.

“We have this saying that from the outside looking in, you can’t understand it, and from the inside looking out, you can’t explain it,” said Sam King, editor in chief of the school newspaper, The Battalion.

Recent decades have brought major changes to this tradition-obsessed school, which was created by the Texas Legislature in 1871 as the Agricultural and Mechanical College of Texas.

It was 1994 when the first woman was elected class president. In 2008, the GLBT Resource Center opened. The university has tried to recruit more minority students and now has a vice president for diversity.

The election of an openly gay student body president was initially hailed as another milestone. Now there are questions about why Mr. Brooks’s opponent was disqualified.

Electoral controversies are nothing new at A&M, said Joseph Puente, who graduated in 2014 with a B.A. in telecommunication media studies. Mr. Puente spent two years as a student senator and in 2012 helped a friend campaign for student body president.

“Students have been slinging mud at each other forever,” he said. “It seems like every year the election isn’t decided until both candidates go in front of the Judicial Court.”

In 2011, John Claybrook won the election for student body president but was disqualified because he exceeded the $1,800 spending limit for his campaign. (That ruling was later overturned and Mr. Claybrook did become president.) In 2015, the student election commissioner resigned under threat of impeachment after ballot errors and multiple campaign violations. The incident was dubbed “Koldusgate” after the name of the building that houses the S.G.A.

“There always seems to be some sort of controversy,” Ms. King said. “I always say that you can’t have an Oreo without milk, and you can’t have a student government election without controversy. But this is definitely the most high-profile disqualification in recent history.”

Mr. Brooks was declared the election winner on Feb. 25 after Mr. McIntosh was disqualified by the student-run Judicial Court. Mr. McIntosh’s appeal was rejected on March 9.

But Mr. Perry remained silent until after the student newspaper published an article highlighting the fact that Mr. Brooks would be A&M’s first openly gay student body president. Mr. Brooks did not hide his sexual orientation, but it was not an issue during the campaign.

The article, which was published last Sunday night, made national news, and may have brought the issue to Mr. Perry’s attention.

At the university’s Memorial Student Center on Thursday, Savannah Harper said she had not read Mr. Perry’s op-ed, but did not understand why everyone was making a fuss about Mr. Brooks being gay.

“I’m not saying that personally I support that lifestyle, but as long as he can do the job, that’s all that matters,” said Ms. Harper, a sophomore and a fourth-generation Aggie.

As for the disqualification of Mr. McIntosh, she cited the Code of Honor, saying that all candidates should follow the election rules.

“If everyone was supposed to report their expenses, then he should have reported the glow sticks,” she said. “That’s why we have the code.”