The blast took place on a moving train near the town of Jaunpur in the state of Uttar Pradesh. The cause of the explosion was not immediately known.
"So far, seven people have died and 38 have been injured in the explosion," Uttar Pradesh police chief Yashpal Singh said.
He said the injured, some of them in serious condition, were admitted to nearby hospitals.
"We still can't say if it was a bomb that exploded in the toilet of an unreserved coach," Singh said. "It could be that somebody was carrying an explosive."
Railways Minister Lalu Prasad Yadav earlier told reporters in the eastern city of Patna it was unclear whether the explosion was caused by a bomb or by the gas cylinder of a cooking stove, sometimes carried by villagers on trains in India.
"There was a blast on an unreserved coach, but it wasn't a very big explosion," Rajendra Singh, a senior railways official, said in Lucknow.
The train was travelling from Patna to the capital New Delhi.
Not very crowded
"Luckily it was not very crowded," Singh said. "The coach didn't jump off the rail. Medical relief has been sent."
"Luckily it was not very crowded. The coach didn't jump off the rail. Medical relief has been sent"
a senior railway official
Singh told reporters that the explosion had been caused by a bomb, but he gave no further details.
Earlier on Thursday, police found a suitcase packed with 18 small bombs inside a passenger train car in eastern Bihar state, said Uday Kant Jha, a railway official in Patna, the state capital.
He said those bombs did not appear to be linked to the train blast.
The suitcase, which was apparently being used to transport the bombs, was found while the train was sitting in a station, he said. Four people had been detained in connection with the suitcase and were being questioned.