BALTIMORE — An Arkansas megachurch pastor was elected Tuesday to lead the country’s Southern Baptists as the conservative denomination tries to turn around declining membership, church attendance and baptisms and faces increasing conflict with mainstream culture, especially over its conviction that gay sex is immoral.

The nation’s largest Protestant denomination also approved a resolution opposing the idea that gender identity can be different from biological sex. The group declined to consider a motion made from the floor by one delegate asking that a Southern California church be disciplined for perceived support of homosexuality. Denomination officials ruled the motion out of order.

In nominating the Rev. Ronnie Floyd for president, the powerful head of Southern Baptist Theological Seminary, the Rev. Albert Mohler, told the crowd of 5,000 meeting in Baltimore, “The nation is embracing a horrifying moral rebellion that is transforming our culture before our very eyes.”

He warned of “direct challenges to our religious freedoms and churches” and said Floyd is the person who can “convey our message in the midst of the most trying times.”

Floyd received 52 percent of the votes from delegates to the annual meeting, beating out the Rev. Dennis Kim, the Korean-American pastor of a bilingual Maryland church, who received 41 percent of the votes.

For 27 years, Floyd has been the pastor at Cross Church in northwest Arkansas, where about 8,500 people worship each week at its several locations. He succeeds the Rev. Fred Luter Jr., who became the 15.7-million-member denomination’s first African-American president in 2012.

Kim’s supporters had hoped to make history again by electing the first Asian president, sending a signal that the denomination associated with white Southern culture is becoming both ethnically and geographically diverse.

David W. Key Sr., the director of Baptist studies at Emory University’s Candler School of Theology, said Kim’s strong showing in the election shows “there’s an element within the SBC that understands demographic realities.”

He said the denomination needs to continue to continue to diversify to reverse its decline.

Delegates also passed, without discussion, a resolution on transgender identity that opposes hormone therapy, gender reassignment surgery and other efforts to “alter one’s bodily identity.”

According to the resolution, “God’s design was the creation of two distinct and complementary sexes, male and female.” The resolution expresses opposition to government efforts to “validate transgender identity as morally praiseworthy.”