They told the militants “to kill them together or leave them alone”, a local governor told Kenyan media.
At least two people were killed in the attack, near the north-eastern village of El Wak on the Somali border.
The Somali based al-Shabab group says it carried out the attack.
The group often carries out attacks in Kenya’s north-east.
The bus was travelling from the capital Nairobi to the town of Mandera.
When al-Shabab killed 148 people in an attack on Garissa University College in April, the militants reportedly singled out Christians and shot them, while freeing many Muslims.
Last year, a bus was attacked near Mandera by al-Shabab militants, who killed 28 non-Muslims travelling to Nairobi for the Christmas holidays.
“The locals showed a sense of patriotism and belonging to each other,” Mandera governor Ali Roba told Kenya’s private Daily Nation newspaper.
The militants decided to leave after the passengers’ show of unity, he added.
Analysis: Bashkas Jugsodaay, Africa Cradle News, Nairobi
The passengers on the bus showed great bravery, but there was another quality revealed by their surprising decision to stand up to the gunmen: Frustration.
The majority of the local population in the north-east are Kenyan Muslims of Somali descent, and they have been hit hard by the consequences of al-Shabab attacks, even if non-Muslims are supposedly the main target of the Somali militant group.
An attack last year in Mandera, in which Christians were killed after being separated from Muslims, caused the departure of more than 2,000 teachers, as well as many health workers who had come from other parts of the country.
Perhaps the passengers felt that the region could simply not afford another such attack.
It will be interesting to see if their actions embolden local populations to increase their resistance to al-Shabab, which has attacked the area several times.
An employee of the Makkah bus company, who had spoken to the driver involved in the attack, confirmed to the BBC that Muslims had refused to be separated from their fellow Christian passengers.
One of the victims was shot dead after trying to run away from the militants after passengers had been forced off the bus, the same employee told the BBC’s Bashkas Jugsodaay in Nairobi.
Al-Shabab has been at war with Kenya ever since Kenyan forces entered Somalia in October 2011 in an effort to crush the militants.
Kenya’s north-eastern region has a large population of ethnic Somalis.
Al-Shabab attacks in Kenya
September 2013 – Al-Shabab militants seize the Westgate shopping mall in the capital Nairobi, killing 67 people.
June 2014 – At least 48 people die after Islamist militants attack hotels and a police station in Mpeketoni, near the island resort of Lamu.
November 2014 – The group targets a bus full of teachers in Mandera County, executing 28 non-Muslims at point-plank range.
December 2014- Al-Shabab kills 36 non-Muslim quarry workers near the north Kenyan town of Mandera.
April 2015 – Militants carry out a massacre at Garissa University College in north-east Kenya, killing 148 people.