Democratic Rep. Beto O'Rourke of Texas took aim at his Republican rival, Sen. Ted Cruz, and his ties to President Donald Trump.

During their first debate amid a closely watched midterm election in Texas, O'Rourke contrasted Cruz's recent conciliatory statements about Trump, with the harsh criticism he had for him when they were both candidates in the 2016 Republican primaries.

O'Rourke rebuked Cruz for aligning himself so closely with Trump, even as the president cozied up with Russian President Vladimir Putin.

"If the president attacks you personally ... how you respond is your business," O'Rourke said to Cruz. "But when the president attacks our institutions, this country, allows a foreign power to invade our democracy, that is our business."

Democratic Rep. Beto O'Rourke of Texas took a verbal swing at his Republican rival, Sen. Ted Cruz, and his ties with President Donald Trump, during a debate on Friday, in the final weeks of a heated and closely watched midterm election in the state.

Speaking at an auditorium at Southern Methodist University in Dallas, O'Rourke contrasted Cruz's recent conciliatory statements about Trump, and the harsh criticism Cruz had for Trump when they were both candidates in the 2016 Republican primary.

Cruz at one time described the future Republican nominee as a "sniveling coward," "big loud New York bully," "pathological liar," and "utterly amoral."

Since then, Cruz has turned a corner, showering praise on Trump after he took office, and describing him as a "flash-bang grenade thrown into Washington by the forgotten men and women of America," in a feature for TIME.

Texans were "[wondering] where their junior senator is" as Trump "enters trade wars and imposes tariffs," O'Rourke said.

"On that stage in Helsinki, as he defended Vladimir Putin instead of the United States of America, that was collusion in action," O'Rourke said, referring to Trump's July summit with Putin in Finland. Trump drew bipartisan backlash during the summit for failing to condemn Russia's meddling in the 2016 US presidential election and criticizing US intelligence officials.

For his part, Cruz offered a tepid rebuke of Trump's Helsinki remarks, without mentioning his name: "I think we need to be acting vigorously to prevent Russian aggression," Cruz said in an interview with CNN. "And I think it's a mistake to be apologizing for Vladimir Putin."

"If the president attacks you personally ... how you respond is your business," O'Rourke said to Cruz. "But when the president attacks our institutions, this country, allows a foreign power to invade our democracy, that is our business."

O'Rourke added that he would be a candidate who would "stand up to this president, [and] where we must, work with him where we can."

Cruz accused the Democratic Party was "just consumed with hatred for Donald Trump," and claiming O'Rourke's views were "extreme, and doesn't reflect Texas."

Polls indicate the race in the traditionally Republican state is a toss-up. An independent Quinnipiac poll released Tuesday suggests Cruz leads O'Rourke by nine percentage points. A Reuters/Ipsos/UVA Center for Politics Poll on Wednesday put O'Rourke in the lead by two points.

Trump endorsed Cruz's campaign and agreed to headline a rally in October: "I'm picking the biggest stadium in Texas we can find," Trump said in a tweet in August.