The bus was travelling to the capital, Nairobi, when it was stopped in Mandera county, not far from the Somali border.
Gunmen separated out non-Muslims by asking passengers to read from the Koran, officials and witnesses said. Those who failed were then shot in the head.
Al-Shabab has carried out a series of attacks in Kenya since 2011.
A statement on a website linked to the Islamist group carried a statement saying the attack was carried out in retaliation for security raids on mosques in the coastal city of Mombasa earlier this week.
Kenya's interior ministry said on its Twitter feed that a camp belonging to the attackers had been destroyed by Kenyan military helicopters and jets, with "many killed".
One of the passengers on the bus, Ahmed Mahat, told the BBC that there were more than 60 passengers on board when it was attacked, before dawn on Saturday, about 30km (19 miles) from Mandera town.
The driver tried to accelerate away, but the vehicle became stuck in mud caused by recent heavy rains, he said.
About 10 heavily armed men talking Somali ordered the passengers off the bus.
"When we got down, passengers were separated according to Somali and non-Somalis," Mr Mahat said.
"The non-Somalis were ordered to read some verses of the holy Koran, and those who failed to read were ordered to lie down. One by one they were shot in the head at point blank range."